nginx reverse proxy with named location: how to override backend header?How to set up Nginx as a caching reverse proxy?Help needed setting up nginx to serve static filesNginx reverse proxy: Not setting expires headerNginx reverse proxy + URL rewritenginx redirect issue with upstream configurationForward Custom Header from Nginx Reverse Proxynginx proxy redirecting request to different proxynginx proxy_pass rewrite of response header locationHow to hide backend URL/URI with Nginx reverse proxyConfigure NGINX : How to handle 500 Error on upstream itself, While Nginx handle other 5xx errors

Can a rogue use Sneak Attack in a Darkness spell cast by another player?

When to remove insignificant variables?

Number of solutions mod p and Betti numbers

How can you guarantee that you won't change/quit job after just couple of months?

Methodology: Writing unit tests for another developer

RandomInteger with equal number of 1 and -1

Prime sieve in Python

Does Doppler effect happen instantly?

Is there any proof that high saturation and contrast makes a picture more appealing in social media?

Count All Possible Unique Combinations of Letters in a Word

How does DC work with natural 20?

Why does the Saturn V have standalone inter-stage rings?

Is there a term for the belief that "if it's legal, it's moral"?

What's currently blocking the construction of the wall between Mexico and the US?

I don't like coffee, neither beer. How to politely work my way around that in a business situation?

UK - Working without a contract. I resign and guy wants to sue me

Heavily limited premature compiler translates text into excecutable python code

What is "industrial ethernet"?

Why does Linux list NVMe drives as /dev/nvme0 instead of /dev/sda?

Concurrent normals conjecture

What can I do with a research project that is my university’s intellectual property?

How did Gollum enter Moria?

What are Elsa's reasons for selecting the Holy Grail on behalf of Donovan?

How long would it take to cross the Channel in 1890's?



nginx reverse proxy with named location: how to override backend header?


How to set up Nginx as a caching reverse proxy?Help needed setting up nginx to serve static filesNginx reverse proxy: Not setting expires headerNginx reverse proxy + URL rewritenginx redirect issue with upstream configurationForward Custom Header from Nginx Reverse Proxynginx proxy redirecting request to different proxynginx proxy_pass rewrite of response header locationHow to hide backend URL/URI with Nginx reverse proxyConfigure NGINX : How to handle 500 Error on upstream itself, While Nginx handle other 5xx errors






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I'm having a difficult time getting add_header to work when try_files is used to send requests to a named location which specifies a backend with proxy_pass.



Basically, I want to override Content-Type for a specific set of URIs, but don't want to use a map to set a variable for it (since I'd like the types and mime.types mechanism to continue working as is), nor to set an extension on the URIs and add more types declarations.



Here's a simplified version of my nginx.conf:



http 
include mime.types;
default_type text/html;
charset utf-8;

server anothertextfile)$
try_files false @backend;
add_header Content-Type 'text/plain' always;
# This has no effect either
# default_type text/plain;





I'm using ngx_aws_auth here, but I don't think that should matter.



The behavior I've seen with nginx 1.16.0 is that Content-Type is not returned at all; not for the /textfile location where I expect text/plain, nor for any other URL where I expect text/html because of the default_type at the http level. If I remove the proxy_hide_header Content-Type line then I simply get the backend's header, which is what I want to override.



I understand the frankly unintuitive behavior of add_header where headers aren't inherited from a higher level if add_header is specified at the current level, which I don't think is happening here, but I also tried moving all header directives to a standalone .conf file and including it everywhere, and I still get the same behavior.



I also tried using the headers-more module, with no difference.



What am I missing, Server Fault?



Thanks!










share|improve this question

















  • 1





    Have you tried switching the line add_header Content-Type 'text/plain' always; to location @backend block?

    – Pothi Kalimuthu
    Jun 5 at 4:07






  • 1





    @PothiKalimuthu That would set 'text/plain' for all backend responses, which I don't want to do. Again, I want to serve 'text/html' as default, and 'text/plain' only for a few specific URIs. In both cases this needs to override the backend's Content-Type.

    – imiric
    Jun 5 at 8:52











  • Okay. Got it. It was my misunderstanding, sorry. In that case, you could resolve the issue by having the exact replica of location @backend block into something like location @custom_backend with an extra line add_header Content-Type 'text/plain' always; in the custom_backend block. If this is confusing, please see my answer with the sample code.

    – Pothi Kalimuthu
    Jun 6 at 2:31

















1















I'm having a difficult time getting add_header to work when try_files is used to send requests to a named location which specifies a backend with proxy_pass.



Basically, I want to override Content-Type for a specific set of URIs, but don't want to use a map to set a variable for it (since I'd like the types and mime.types mechanism to continue working as is), nor to set an extension on the URIs and add more types declarations.



Here's a simplified version of my nginx.conf:



http 
include mime.types;
default_type text/html;
charset utf-8;

server anothertextfile)$
try_files false @backend;
add_header Content-Type 'text/plain' always;
# This has no effect either
# default_type text/plain;





I'm using ngx_aws_auth here, but I don't think that should matter.



The behavior I've seen with nginx 1.16.0 is that Content-Type is not returned at all; not for the /textfile location where I expect text/plain, nor for any other URL where I expect text/html because of the default_type at the http level. If I remove the proxy_hide_header Content-Type line then I simply get the backend's header, which is what I want to override.



I understand the frankly unintuitive behavior of add_header where headers aren't inherited from a higher level if add_header is specified at the current level, which I don't think is happening here, but I also tried moving all header directives to a standalone .conf file and including it everywhere, and I still get the same behavior.



I also tried using the headers-more module, with no difference.



What am I missing, Server Fault?



Thanks!










share|improve this question

















  • 1





    Have you tried switching the line add_header Content-Type 'text/plain' always; to location @backend block?

    – Pothi Kalimuthu
    Jun 5 at 4:07






  • 1





    @PothiKalimuthu That would set 'text/plain' for all backend responses, which I don't want to do. Again, I want to serve 'text/html' as default, and 'text/plain' only for a few specific URIs. In both cases this needs to override the backend's Content-Type.

    – imiric
    Jun 5 at 8:52











  • Okay. Got it. It was my misunderstanding, sorry. In that case, you could resolve the issue by having the exact replica of location @backend block into something like location @custom_backend with an extra line add_header Content-Type 'text/plain' always; in the custom_backend block. If this is confusing, please see my answer with the sample code.

    – Pothi Kalimuthu
    Jun 6 at 2:31













1












1








1








I'm having a difficult time getting add_header to work when try_files is used to send requests to a named location which specifies a backend with proxy_pass.



Basically, I want to override Content-Type for a specific set of URIs, but don't want to use a map to set a variable for it (since I'd like the types and mime.types mechanism to continue working as is), nor to set an extension on the URIs and add more types declarations.



Here's a simplified version of my nginx.conf:



http 
include mime.types;
default_type text/html;
charset utf-8;

server anothertextfile)$
try_files false @backend;
add_header Content-Type 'text/plain' always;
# This has no effect either
# default_type text/plain;





I'm using ngx_aws_auth here, but I don't think that should matter.



The behavior I've seen with nginx 1.16.0 is that Content-Type is not returned at all; not for the /textfile location where I expect text/plain, nor for any other URL where I expect text/html because of the default_type at the http level. If I remove the proxy_hide_header Content-Type line then I simply get the backend's header, which is what I want to override.



I understand the frankly unintuitive behavior of add_header where headers aren't inherited from a higher level if add_header is specified at the current level, which I don't think is happening here, but I also tried moving all header directives to a standalone .conf file and including it everywhere, and I still get the same behavior.



I also tried using the headers-more module, with no difference.



What am I missing, Server Fault?



Thanks!










share|improve this question














I'm having a difficult time getting add_header to work when try_files is used to send requests to a named location which specifies a backend with proxy_pass.



Basically, I want to override Content-Type for a specific set of URIs, but don't want to use a map to set a variable for it (since I'd like the types and mime.types mechanism to continue working as is), nor to set an extension on the URIs and add more types declarations.



Here's a simplified version of my nginx.conf:



http 
include mime.types;
default_type text/html;
charset utf-8;

server anothertextfile)$
try_files false @backend;
add_header Content-Type 'text/plain' always;
# This has no effect either
# default_type text/plain;





I'm using ngx_aws_auth here, but I don't think that should matter.



The behavior I've seen with nginx 1.16.0 is that Content-Type is not returned at all; not for the /textfile location where I expect text/plain, nor for any other URL where I expect text/html because of the default_type at the http level. If I remove the proxy_hide_header Content-Type line then I simply get the backend's header, which is what I want to override.



I understand the frankly unintuitive behavior of add_header where headers aren't inherited from a higher level if add_header is specified at the current level, which I don't think is happening here, but I also tried moving all header directives to a standalone .conf file and including it everywhere, and I still get the same behavior.



I also tried using the headers-more module, with no difference.



What am I missing, Server Fault?



Thanks!







nginx reverse-proxy http-headers






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jun 4 at 21:27









imiricimiric

11814




11814







  • 1





    Have you tried switching the line add_header Content-Type 'text/plain' always; to location @backend block?

    – Pothi Kalimuthu
    Jun 5 at 4:07






  • 1





    @PothiKalimuthu That would set 'text/plain' for all backend responses, which I don't want to do. Again, I want to serve 'text/html' as default, and 'text/plain' only for a few specific URIs. In both cases this needs to override the backend's Content-Type.

    – imiric
    Jun 5 at 8:52











  • Okay. Got it. It was my misunderstanding, sorry. In that case, you could resolve the issue by having the exact replica of location @backend block into something like location @custom_backend with an extra line add_header Content-Type 'text/plain' always; in the custom_backend block. If this is confusing, please see my answer with the sample code.

    – Pothi Kalimuthu
    Jun 6 at 2:31












  • 1





    Have you tried switching the line add_header Content-Type 'text/plain' always; to location @backend block?

    – Pothi Kalimuthu
    Jun 5 at 4:07






  • 1





    @PothiKalimuthu That would set 'text/plain' for all backend responses, which I don't want to do. Again, I want to serve 'text/html' as default, and 'text/plain' only for a few specific URIs. In both cases this needs to override the backend's Content-Type.

    – imiric
    Jun 5 at 8:52











  • Okay. Got it. It was my misunderstanding, sorry. In that case, you could resolve the issue by having the exact replica of location @backend block into something like location @custom_backend with an extra line add_header Content-Type 'text/plain' always; in the custom_backend block. If this is confusing, please see my answer with the sample code.

    – Pothi Kalimuthu
    Jun 6 at 2:31







1




1





Have you tried switching the line add_header Content-Type 'text/plain' always; to location @backend block?

– Pothi Kalimuthu
Jun 5 at 4:07





Have you tried switching the line add_header Content-Type 'text/plain' always; to location @backend block?

– Pothi Kalimuthu
Jun 5 at 4:07




1




1





@PothiKalimuthu That would set 'text/plain' for all backend responses, which I don't want to do. Again, I want to serve 'text/html' as default, and 'text/plain' only for a few specific URIs. In both cases this needs to override the backend's Content-Type.

– imiric
Jun 5 at 8:52





@PothiKalimuthu That would set 'text/plain' for all backend responses, which I don't want to do. Again, I want to serve 'text/html' as default, and 'text/plain' only for a few specific URIs. In both cases this needs to override the backend's Content-Type.

– imiric
Jun 5 at 8:52













Okay. Got it. It was my misunderstanding, sorry. In that case, you could resolve the issue by having the exact replica of location @backend block into something like location @custom_backend with an extra line add_header Content-Type 'text/plain' always; in the custom_backend block. If this is confusing, please see my answer with the sample code.

– Pothi Kalimuthu
Jun 6 at 2:31





Okay. Got it. It was my misunderstanding, sorry. In that case, you could resolve the issue by having the exact replica of location @backend block into something like location @custom_backend with an extra line add_header Content-Type 'text/plain' always; in the custom_backend block. If this is confusing, please see my answer with the sample code.

– Pothi Kalimuthu
Jun 6 at 2:31










1 Answer
1






active

oldest

votes


















1














The solution is to use an additional named block to have a custom header for all the requests pass through it. The code in the original question didn't work because add_header is effective only on the last matched location block. If a request passes through multiple location blocks, it doesn't pick up add_header directive on the passed location blocks. Nginx only considers or looks for add_header in the last matched location block. In this case, the named location block is the last matched location block. I hope that clarifies why the original code didn't work as expected.



http 
include mime.types;
default_type text/html;
charset utf-8;

server
listen 80;

location @backend
rewrite ^ /proxy$uri break;
proxy_pass https://backend;
proxy_intercept_errors on;

aws_access_key ***;
aws_secret_key ***;
s3_bucket ***;
chop_prefix /proxy;

proxy_set_header Authorization $s3_auth_token;
proxy_set_header x-amz-date $aws_date;
proxy_hide_header Content-Type;


location @plain_backend
rewrite ^ /proxy$uri break;
proxy_pass https://backend;
proxy_intercept_errors on;

aws_access_key ***;
aws_secret_key ***;
s3_bucket ***;
chop_prefix /proxy;

proxy_set_header Authorization $s3_auth_token;
proxy_set_header x-amz-date $aws_date;
proxy_hide_header Content-Type;

add_header Content-Type 'text/plain' always;


location /
try_files false @backend;


location ~ /(textfile






share|improve this answer


















  • 1





    Thanks, that does indeed work. I was trying to avoid duplication, but that is easily remedied with include. It's just unintuitive how add_header behaves, and ultimately I reverted to using map to set a custom Content-Type variable, since there's seemingly no way to use this named location approach while retaining the types/mime.types functionality, as this poor fella wanted as well. It's surprising to me that something so basic (overriding backend headers) is so difficult to do with nginx. Thanks again!

    – imiric
    Jun 6 at 21:49











  • Good to know that you switched to map. There are indeed multiple ways to solve an issue with Nginx. None of them are clean and easy. However, with the introduction of njs, the future of Nginx customization looks promising. When njs becomes a standard module, there will be a paradigm shift on everything about Nginx.

    – Pothi Kalimuthu
    Jun 7 at 0:26






  • 1





    Interesting, I hadn't heard about njs. It sounds like Lua/OpenResty, and FWIW what I wanted to do can be accomplished with Lua, according to this comment, though I haven't tried it. I don't want to add that kind of extensibility/complexity when nginx should be capable of doing it OOB.

    – imiric
    Jun 7 at 10:37











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
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f970139%2fnginx-reverse-proxy-with-named-location-how-to-override-backend-header%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









1














The solution is to use an additional named block to have a custom header for all the requests pass through it. The code in the original question didn't work because add_header is effective only on the last matched location block. If a request passes through multiple location blocks, it doesn't pick up add_header directive on the passed location blocks. Nginx only considers or looks for add_header in the last matched location block. In this case, the named location block is the last matched location block. I hope that clarifies why the original code didn't work as expected.



http 
include mime.types;
default_type text/html;
charset utf-8;

server
listen 80;

location @backend
rewrite ^ /proxy$uri break;
proxy_pass https://backend;
proxy_intercept_errors on;

aws_access_key ***;
aws_secret_key ***;
s3_bucket ***;
chop_prefix /proxy;

proxy_set_header Authorization $s3_auth_token;
proxy_set_header x-amz-date $aws_date;
proxy_hide_header Content-Type;


location @plain_backend
rewrite ^ /proxy$uri break;
proxy_pass https://backend;
proxy_intercept_errors on;

aws_access_key ***;
aws_secret_key ***;
s3_bucket ***;
chop_prefix /proxy;

proxy_set_header Authorization $s3_auth_token;
proxy_set_header x-amz-date $aws_date;
proxy_hide_header Content-Type;

add_header Content-Type 'text/plain' always;


location /
try_files false @backend;


location ~ /(textfile






share|improve this answer


















  • 1





    Thanks, that does indeed work. I was trying to avoid duplication, but that is easily remedied with include. It's just unintuitive how add_header behaves, and ultimately I reverted to using map to set a custom Content-Type variable, since there's seemingly no way to use this named location approach while retaining the types/mime.types functionality, as this poor fella wanted as well. It's surprising to me that something so basic (overriding backend headers) is so difficult to do with nginx. Thanks again!

    – imiric
    Jun 6 at 21:49











  • Good to know that you switched to map. There are indeed multiple ways to solve an issue with Nginx. None of them are clean and easy. However, with the introduction of njs, the future of Nginx customization looks promising. When njs becomes a standard module, there will be a paradigm shift on everything about Nginx.

    – Pothi Kalimuthu
    Jun 7 at 0:26






  • 1





    Interesting, I hadn't heard about njs. It sounds like Lua/OpenResty, and FWIW what I wanted to do can be accomplished with Lua, according to this comment, though I haven't tried it. I don't want to add that kind of extensibility/complexity when nginx should be capable of doing it OOB.

    – imiric
    Jun 7 at 10:37















1














The solution is to use an additional named block to have a custom header for all the requests pass through it. The code in the original question didn't work because add_header is effective only on the last matched location block. If a request passes through multiple location blocks, it doesn't pick up add_header directive on the passed location blocks. Nginx only considers or looks for add_header in the last matched location block. In this case, the named location block is the last matched location block. I hope that clarifies why the original code didn't work as expected.



http 
include mime.types;
default_type text/html;
charset utf-8;

server
listen 80;

location @backend
rewrite ^ /proxy$uri break;
proxy_pass https://backend;
proxy_intercept_errors on;

aws_access_key ***;
aws_secret_key ***;
s3_bucket ***;
chop_prefix /proxy;

proxy_set_header Authorization $s3_auth_token;
proxy_set_header x-amz-date $aws_date;
proxy_hide_header Content-Type;


location @plain_backend
rewrite ^ /proxy$uri break;
proxy_pass https://backend;
proxy_intercept_errors on;

aws_access_key ***;
aws_secret_key ***;
s3_bucket ***;
chop_prefix /proxy;

proxy_set_header Authorization $s3_auth_token;
proxy_set_header x-amz-date $aws_date;
proxy_hide_header Content-Type;

add_header Content-Type 'text/plain' always;


location /
try_files false @backend;


location ~ /(textfile






share|improve this answer


















  • 1





    Thanks, that does indeed work. I was trying to avoid duplication, but that is easily remedied with include. It's just unintuitive how add_header behaves, and ultimately I reverted to using map to set a custom Content-Type variable, since there's seemingly no way to use this named location approach while retaining the types/mime.types functionality, as this poor fella wanted as well. It's surprising to me that something so basic (overriding backend headers) is so difficult to do with nginx. Thanks again!

    – imiric
    Jun 6 at 21:49











  • Good to know that you switched to map. There are indeed multiple ways to solve an issue with Nginx. None of them are clean and easy. However, with the introduction of njs, the future of Nginx customization looks promising. When njs becomes a standard module, there will be a paradigm shift on everything about Nginx.

    – Pothi Kalimuthu
    Jun 7 at 0:26






  • 1





    Interesting, I hadn't heard about njs. It sounds like Lua/OpenResty, and FWIW what I wanted to do can be accomplished with Lua, according to this comment, though I haven't tried it. I don't want to add that kind of extensibility/complexity when nginx should be capable of doing it OOB.

    – imiric
    Jun 7 at 10:37













1












1








1







The solution is to use an additional named block to have a custom header for all the requests pass through it. The code in the original question didn't work because add_header is effective only on the last matched location block. If a request passes through multiple location blocks, it doesn't pick up add_header directive on the passed location blocks. Nginx only considers or looks for add_header in the last matched location block. In this case, the named location block is the last matched location block. I hope that clarifies why the original code didn't work as expected.



http 
include mime.types;
default_type text/html;
charset utf-8;

server
listen 80;

location @backend
rewrite ^ /proxy$uri break;
proxy_pass https://backend;
proxy_intercept_errors on;

aws_access_key ***;
aws_secret_key ***;
s3_bucket ***;
chop_prefix /proxy;

proxy_set_header Authorization $s3_auth_token;
proxy_set_header x-amz-date $aws_date;
proxy_hide_header Content-Type;


location @plain_backend
rewrite ^ /proxy$uri break;
proxy_pass https://backend;
proxy_intercept_errors on;

aws_access_key ***;
aws_secret_key ***;
s3_bucket ***;
chop_prefix /proxy;

proxy_set_header Authorization $s3_auth_token;
proxy_set_header x-amz-date $aws_date;
proxy_hide_header Content-Type;

add_header Content-Type 'text/plain' always;


location /
try_files false @backend;


location ~ /(textfile






share|improve this answer













The solution is to use an additional named block to have a custom header for all the requests pass through it. The code in the original question didn't work because add_header is effective only on the last matched location block. If a request passes through multiple location blocks, it doesn't pick up add_header directive on the passed location blocks. Nginx only considers or looks for add_header in the last matched location block. In this case, the named location block is the last matched location block. I hope that clarifies why the original code didn't work as expected.



http 
include mime.types;
default_type text/html;
charset utf-8;

server
listen 80;

location @backend
rewrite ^ /proxy$uri break;
proxy_pass https://backend;
proxy_intercept_errors on;

aws_access_key ***;
aws_secret_key ***;
s3_bucket ***;
chop_prefix /proxy;

proxy_set_header Authorization $s3_auth_token;
proxy_set_header x-amz-date $aws_date;
proxy_hide_header Content-Type;


location @plain_backend
rewrite ^ /proxy$uri break;
proxy_pass https://backend;
proxy_intercept_errors on;

aws_access_key ***;
aws_secret_key ***;
s3_bucket ***;
chop_prefix /proxy;

proxy_set_header Authorization $s3_auth_token;
proxy_set_header x-amz-date $aws_date;
proxy_hide_header Content-Type;

add_header Content-Type 'text/plain' always;


location /
try_files false @backend;


location ~ /(textfile







share|improve this answer












share|improve this answer



share|improve this answer










answered Jun 6 at 2:36









Pothi KalimuthuPothi Kalimuthu

3,94411934




3,94411934







  • 1





    Thanks, that does indeed work. I was trying to avoid duplication, but that is easily remedied with include. It's just unintuitive how add_header behaves, and ultimately I reverted to using map to set a custom Content-Type variable, since there's seemingly no way to use this named location approach while retaining the types/mime.types functionality, as this poor fella wanted as well. It's surprising to me that something so basic (overriding backend headers) is so difficult to do with nginx. Thanks again!

    – imiric
    Jun 6 at 21:49











  • Good to know that you switched to map. There are indeed multiple ways to solve an issue with Nginx. None of them are clean and easy. However, with the introduction of njs, the future of Nginx customization looks promising. When njs becomes a standard module, there will be a paradigm shift on everything about Nginx.

    – Pothi Kalimuthu
    Jun 7 at 0:26






  • 1





    Interesting, I hadn't heard about njs. It sounds like Lua/OpenResty, and FWIW what I wanted to do can be accomplished with Lua, according to this comment, though I haven't tried it. I don't want to add that kind of extensibility/complexity when nginx should be capable of doing it OOB.

    – imiric
    Jun 7 at 10:37












  • 1





    Thanks, that does indeed work. I was trying to avoid duplication, but that is easily remedied with include. It's just unintuitive how add_header behaves, and ultimately I reverted to using map to set a custom Content-Type variable, since there's seemingly no way to use this named location approach while retaining the types/mime.types functionality, as this poor fella wanted as well. It's surprising to me that something so basic (overriding backend headers) is so difficult to do with nginx. Thanks again!

    – imiric
    Jun 6 at 21:49











  • Good to know that you switched to map. There are indeed multiple ways to solve an issue with Nginx. None of them are clean and easy. However, with the introduction of njs, the future of Nginx customization looks promising. When njs becomes a standard module, there will be a paradigm shift on everything about Nginx.

    – Pothi Kalimuthu
    Jun 7 at 0:26






  • 1





    Interesting, I hadn't heard about njs. It sounds like Lua/OpenResty, and FWIW what I wanted to do can be accomplished with Lua, according to this comment, though I haven't tried it. I don't want to add that kind of extensibility/complexity when nginx should be capable of doing it OOB.

    – imiric
    Jun 7 at 10:37







1




1





Thanks, that does indeed work. I was trying to avoid duplication, but that is easily remedied with include. It's just unintuitive how add_header behaves, and ultimately I reverted to using map to set a custom Content-Type variable, since there's seemingly no way to use this named location approach while retaining the types/mime.types functionality, as this poor fella wanted as well. It's surprising to me that something so basic (overriding backend headers) is so difficult to do with nginx. Thanks again!

– imiric
Jun 6 at 21:49





Thanks, that does indeed work. I was trying to avoid duplication, but that is easily remedied with include. It's just unintuitive how add_header behaves, and ultimately I reverted to using map to set a custom Content-Type variable, since there's seemingly no way to use this named location approach while retaining the types/mime.types functionality, as this poor fella wanted as well. It's surprising to me that something so basic (overriding backend headers) is so difficult to do with nginx. Thanks again!

– imiric
Jun 6 at 21:49













Good to know that you switched to map. There are indeed multiple ways to solve an issue with Nginx. None of them are clean and easy. However, with the introduction of njs, the future of Nginx customization looks promising. When njs becomes a standard module, there will be a paradigm shift on everything about Nginx.

– Pothi Kalimuthu
Jun 7 at 0:26





Good to know that you switched to map. There are indeed multiple ways to solve an issue with Nginx. None of them are clean and easy. However, with the introduction of njs, the future of Nginx customization looks promising. When njs becomes a standard module, there will be a paradigm shift on everything about Nginx.

– Pothi Kalimuthu
Jun 7 at 0:26




1




1





Interesting, I hadn't heard about njs. It sounds like Lua/OpenResty, and FWIW what I wanted to do can be accomplished with Lua, according to this comment, though I haven't tried it. I don't want to add that kind of extensibility/complexity when nginx should be capable of doing it OOB.

– imiric
Jun 7 at 10:37





Interesting, I hadn't heard about njs. It sounds like Lua/OpenResty, and FWIW what I wanted to do can be accomplished with Lua, according to this comment, though I haven't tried it. I don't want to add that kind of extensibility/complexity when nginx should be capable of doing it OOB.

– imiric
Jun 7 at 10:37

















draft saved

draft discarded
















































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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f970139%2fnginx-reverse-proxy-with-named-location-how-to-override-backend-header%23new-answer', 'question_page');

);

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







Popular posts from this blog

Club Baloncesto Breogán Índice Historia | Pavillón | Nome | O Breogán na cultura popular | Xogadores | Adestradores | Presidentes | Palmarés | Historial | Líderes | Notas | Véxase tamén | Menú de navegacióncbbreogan.galCadroGuía oficial da ACB 2009-10, páxina 201Guía oficial ACB 1992, páxina 183. Editorial DB.É de 6.500 espectadores sentados axeitándose á última normativa"Estudiantes Junior, entre as mellores canteiras"o orixinalHemeroteca El Mundo Deportivo, 16 setembro de 1970, páxina 12Historia do BreogánAlfredo Pérez, o último canoneiroHistoria C.B. BreogánHemeroteca de El Mundo DeportivoJimmy Wright, norteamericano do Breogán deixará Lugo por ameazas de morteResultados de Breogán en 1986-87Resultados de Breogán en 1990-91Ficha de Velimir Perasović en acb.comResultados de Breogán en 1994-95Breogán arrasa al Barça. "El Mundo Deportivo", 27 de setembro de 1999, páxina 58CB Breogán - FC BarcelonaA FEB invita a participar nunha nova Liga EuropeaCharlie Bell na prensa estatalMáximos anotadores 2005Tempada 2005-06 : Tódolos Xogadores da Xornada""Non quero pensar nunha man negra, mais pregúntome que está a pasar""o orixinalRaúl López, orgulloso dos xogadores, presume da boa saúde económica do BreogánJulio González confirma que cesa como presidente del BreogánHomenaxe a Lisardo GómezA tempada do rexurdimento celesteEntrevista a Lisardo GómezEl COB dinamita el Pazo para forzar el quinto (69-73)Cafés Candelas, patrocinador del CB Breogán"Suso Lázare, novo presidente do Breogán"o orixinalCafés Candelas Breogán firma el mayor triunfo de la historiaEl Breogán realizará 17 homenajes por su cincuenta aniversario"O Breogán honra ao seu fundador e primeiro presidente"o orixinalMiguel Giao recibiu a homenaxe do PazoHomenaxe aos primeiros gladiadores celestesO home que nos amosa como ver o Breo co corazónTita Franco será homenaxeada polos #50anosdeBreoJulio Vila recibirá unha homenaxe in memoriam polos #50anosdeBreo"O Breogán homenaxeará aos seus aboados máis veteráns"Pechada ovación a «Capi» Sanmartín e Ricardo «Corazón de González»Homenaxe por décadas de informaciónPaco García volve ao Pazo con motivo do 50 aniversario"Resultados y clasificaciones""O Cafés Candelas Breogán, campión da Copa Princesa""O Cafés Candelas Breogán, equipo ACB"C.B. Breogán"Proxecto social"o orixinal"Centros asociados"o orixinalFicha en imdb.comMario Camus trata la recuperación del amor en 'La vieja música', su última película"Páxina web oficial""Club Baloncesto Breogán""C. B. Breogán S.A.D."eehttp://www.fegaba.com

Vilaño, A Laracha Índice Patrimonio | Lugares e parroquias | Véxase tamén | Menú de navegación43°14′52″N 8°36′03″O / 43.24775, -8.60070

Cegueira Índice Epidemioloxía | Deficiencia visual | Tipos de cegueira | Principais causas de cegueira | Tratamento | Técnicas de adaptación e axudas | Vida dos cegos | Primeiros auxilios | Crenzas respecto das persoas cegas | Crenzas das persoas cegas | O neno deficiente visual | Aspectos psicolóxicos da cegueira | Notas | Véxase tamén | Menú de navegación54.054.154.436928256blindnessDicionario da Real Academia GalegaPortal das Palabras"International Standards: Visual Standards — Aspects and Ranges of Vision Loss with Emphasis on Population Surveys.""Visual impairment and blindness""Presentan un plan para previr a cegueira"o orixinalACCDV Associació Catalana de Cecs i Disminuïts Visuals - PMFTrachoma"Effect of gene therapy on visual function in Leber's congenital amaurosis"1844137110.1056/NEJMoa0802268Cans guía - os mellores amigos dos cegosArquivadoEscola de cans guía para cegos en Mortágua, PortugalArquivado"Tecnología para ciegos y deficientes visuales. Recopilación de recursos gratuitos en la Red""Colorino""‘COL.diesis’, escuchar los sonidos del color""COL.diesis: Transforming Colour into Melody and Implementing the Result in a Colour Sensor Device"o orixinal"Sistema de desarrollo de sinestesia color-sonido para invidentes utilizando un protocolo de audio""Enseñanza táctil - geometría y color. Juegos didácticos para niños ciegos y videntes""Sistema Constanz"L'ocupació laboral dels cecs a l'Estat espanyol està pràcticament equiparada a la de les persones amb visió, entrevista amb Pedro ZuritaONCE (Organización Nacional de Cegos de España)Prevención da cegueiraDescrición de deficiencias visuais (Disc@pnet)Braillín, un boneco atractivo para calquera neno, con ou sen discapacidade, que permite familiarizarse co sistema de escritura e lectura brailleAxudas Técnicas36838ID00897494007150-90057129528256DOID:1432HP:0000618D001766C10.597.751.941.162C97109C0155020