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

Wikipedia:Vital articles Мазмуну Biography - Өмүр баян Philosophy and psychology - Философия жана психология Religion - Дин Social sciences - Коомдук илимдер Language and literature - Тил жана адабият Science - Илим Technology - Технология Arts and recreation - Искусство жана эс алуу History and geography - Тарых жана география Навигация менюсу

Bruxelas-Capital Índice Historia | Composición | Situación lingüística | Clima | Cidades irmandadas | Notas | Véxase tamén | Menú de navegacióneO uso das linguas en Bruxelas e a situación do neerlandés"Rexión de Bruxelas Capital"o orixinalSitio da rexiónPáxina de Bruselas no sitio da Oficina de Promoción Turística de Valonia e BruxelasMapa Interactivo da Rexión de Bruxelas-CapitaleeWorldCat332144929079854441105155190212ID28008674080552-90000 0001 0666 3698n94104302ID540940339365017018237

What should I write in an apology letter, since I have decided not to join a company after accepting an offer letterShould I keep looking after accepting a job offer?What should I do when I've been verbally told I would get an offer letter, but still haven't gotten one after 4 weeks?Do I accept an offer from a company that I am not likely to join?New job hasn't confirmed starting date and I want to give current employer as much notice as possibleHow should I address my manager in my resignation letter?HR delayed background verification, now jobless as resignedNo email communication after accepting a formal written offer. How should I phrase the call?What should I do if after receiving a verbal offer letter I am informed that my written job offer is put on hold due to some internal issues?Should I inform the current employer that I am about to resign within 1-2 weeks since I have signed the offer letter and waiting for visa?What company will do, if I send their offer letter to another company