How to configure nginx to force download on a query paramIn Nginx, how can I rewrite all http requests to...
How should I state my MS degree in my CV when it was in practice a joint-program?
If all harmonics are generated by plucking, how does a guitar string produce a pure frequency sound?
Has the Isbell–Freyd criterion ever been used to check that a category is concretisable?
Can I retract my name from an already published manuscript?
Word to be used for "standing with your toes pointing out"
I am on the US no-fly list. What can I do in order to be allowed on flights which go through US airspace?
Why is this code uniquely decodable?
Quenching swords in dragon blood; why?
Avoiding morning and evening handshakes
What can I substitute for soda pop in a sweet pork recipe?
Do authors have to be politically correct in article-writing?
What are these green text/line displays shown during the livestream of Crew Dragon's approach to dock with the ISS?
How would an AI self awareness kill switch work?
Criticizing long fiction. How is it different from short?
Could be quantum mechanics necessary to analyze some biology scenarios?
How to avoid being sexist when trying to employ someone to function in a very sexist environment?
Is the theory of the category of topological spaces computable?
Why is c4 a better move in this position?
Can a person refuse a presidential pardon?
What's the rationale behind the objections to these measures against human trafficking?
Predict mars robot position
What to do when being responsible for data protection in your lab, yet advice is ignored?
Connecting top and bottom of adjacent circles
Why is commutativity optional in multiplication for rings?
How to configure nginx to force download on a query param
In Nginx, how can I rewrite all http requests to https while maintaining sub-domain?How to force or redirect to SSL in nginx?Configure php5-fpm for many concurrent usersPHP app breaks on Nginx, but works on Apachenginx rewrite throw 404 with last and breakWordPress Nginx Browser Cache Expires on Extentionless URLsHow to cache images in nginx, but allow to override cache?Nginx regex rule for caching images override the root location blockNGINX virtual host config for Magento2 in a subfolderPass request uri to proxy as query param Nginx
So that /media/file.jpg
opens in browser and /media/file.jpg?dl=1
forces browser to download.
Here's my current config, that doesn't work:
location /media/ {
autoindex off;
root /home/my_app/media/;
location ~* .(?:ico|css|js|gif|jpe?g|png)$ {
expires 365d;
add_header Pragma public;
add_header Cache-Control "public";
}
# Allow forcing download by query param `dl`
if ($arg_dl = "1") { # why this doesn't work?
add_header Content-disposition "attachment; filename=$1";
}
}
nginx
bumped to the homepage by Community♦ 13 hours ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
So that /media/file.jpg
opens in browser and /media/file.jpg?dl=1
forces browser to download.
Here's my current config, that doesn't work:
location /media/ {
autoindex off;
root /home/my_app/media/;
location ~* .(?:ico|css|js|gif|jpe?g|png)$ {
expires 365d;
add_header Pragma public;
add_header Cache-Control "public";
}
# Allow forcing download by query param `dl`
if ($arg_dl = "1") { # why this doesn't work?
add_header Content-disposition "attachment; filename=$1";
}
}
nginx
bumped to the homepage by Community♦ 13 hours ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
So that /media/file.jpg
opens in browser and /media/file.jpg?dl=1
forces browser to download.
Here's my current config, that doesn't work:
location /media/ {
autoindex off;
root /home/my_app/media/;
location ~* .(?:ico|css|js|gif|jpe?g|png)$ {
expires 365d;
add_header Pragma public;
add_header Cache-Control "public";
}
# Allow forcing download by query param `dl`
if ($arg_dl = "1") { # why this doesn't work?
add_header Content-disposition "attachment; filename=$1";
}
}
nginx
So that /media/file.jpg
opens in browser and /media/file.jpg?dl=1
forces browser to download.
Here's my current config, that doesn't work:
location /media/ {
autoindex off;
root /home/my_app/media/;
location ~* .(?:ico|css|js|gif|jpe?g|png)$ {
expires 365d;
add_header Pragma public;
add_header Cache-Control "public";
}
# Allow forcing download by query param `dl`
if ($arg_dl = "1") { # why this doesn't work?
add_header Content-disposition "attachment; filename=$1";
}
}
nginx
nginx
asked Aug 6 '15 at 17:32
gruchagrucha
438169
438169
bumped to the homepage by Community♦ 13 hours ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 13 hours ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
The if
statement is never reached, because only the location
is matched when a file is requested.
If the URL /media/
is in /home/my_app/media/
directory, you cannot use root
like that. You need to either use alias /home/my_app/media/
or root /home/my_app/
.
You should try this (updated version):
location ~* ^/media/.+.(?:ico|css|js|gif|jpe?g|png)$ {
autoindex off;
root /home/my_app/media/;
expires 365d;
add_header Pragma public;
add_header Cache-Control "public";
if ($arg_dl = "1") {
add_header Content-disposition "attachment; filename=$1";
}
}
nested location is not good idea, why not combing them into one?
– Anatoly
Aug 6 '15 at 22:25
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "2"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f711383%2fhow-to-configure-nginx-to-force-download-on-a-query-param%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The if
statement is never reached, because only the location
is matched when a file is requested.
If the URL /media/
is in /home/my_app/media/
directory, you cannot use root
like that. You need to either use alias /home/my_app/media/
or root /home/my_app/
.
You should try this (updated version):
location ~* ^/media/.+.(?:ico|css|js|gif|jpe?g|png)$ {
autoindex off;
root /home/my_app/media/;
expires 365d;
add_header Pragma public;
add_header Cache-Control "public";
if ($arg_dl = "1") {
add_header Content-disposition "attachment; filename=$1";
}
}
nested location is not good idea, why not combing them into one?
– Anatoly
Aug 6 '15 at 22:25
add a comment |
The if
statement is never reached, because only the location
is matched when a file is requested.
If the URL /media/
is in /home/my_app/media/
directory, you cannot use root
like that. You need to either use alias /home/my_app/media/
or root /home/my_app/
.
You should try this (updated version):
location ~* ^/media/.+.(?:ico|css|js|gif|jpe?g|png)$ {
autoindex off;
root /home/my_app/media/;
expires 365d;
add_header Pragma public;
add_header Cache-Control "public";
if ($arg_dl = "1") {
add_header Content-disposition "attachment; filename=$1";
}
}
nested location is not good idea, why not combing them into one?
– Anatoly
Aug 6 '15 at 22:25
add a comment |
The if
statement is never reached, because only the location
is matched when a file is requested.
If the URL /media/
is in /home/my_app/media/
directory, you cannot use root
like that. You need to either use alias /home/my_app/media/
or root /home/my_app/
.
You should try this (updated version):
location ~* ^/media/.+.(?:ico|css|js|gif|jpe?g|png)$ {
autoindex off;
root /home/my_app/media/;
expires 365d;
add_header Pragma public;
add_header Cache-Control "public";
if ($arg_dl = "1") {
add_header Content-disposition "attachment; filename=$1";
}
}
The if
statement is never reached, because only the location
is matched when a file is requested.
If the URL /media/
is in /home/my_app/media/
directory, you cannot use root
like that. You need to either use alias /home/my_app/media/
or root /home/my_app/
.
You should try this (updated version):
location ~* ^/media/.+.(?:ico|css|js|gif|jpe?g|png)$ {
autoindex off;
root /home/my_app/media/;
expires 365d;
add_header Pragma public;
add_header Cache-Control "public";
if ($arg_dl = "1") {
add_header Content-disposition "attachment; filename=$1";
}
}
edited Aug 8 '15 at 6:30
answered Aug 6 '15 at 18:53
Tero KilkanenTero Kilkanen
20.2k22644
20.2k22644
nested location is not good idea, why not combing them into one?
– Anatoly
Aug 6 '15 at 22:25
add a comment |
nested location is not good idea, why not combing them into one?
– Anatoly
Aug 6 '15 at 22:25
nested location is not good idea, why not combing them into one?
– Anatoly
Aug 6 '15 at 22:25
nested location is not good idea, why not combing them into one?
– Anatoly
Aug 6 '15 at 22:25
add a comment |
Thanks for contributing an answer to Server Fault!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f711383%2fhow-to-configure-nginx-to-force-download-on-a-query-param%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown