Is is possible to define a single nginx location in two separate blocks? -


is possible define single nginx location in 2 separate blocks?

for example:

server {   listen *:80;   server_name someserver;    location / {     proxy_cache off;   }    location /assets {     proxy_cache mycache;   }    # need second root location   # append 1st? if it's possible.   location / {     proxy_pass http://foo;   } } 

the idea root location becomes:

location / {   proxy_cache off;   proxy_pass http://foo; } 

if you'd know more why, read on.


background:

i'm running gitlab omnibus installation. according docs, admin inject custom nginx config gitlab server block.

however, injection adds things end server block rather specific location block.

so if try inject include my_config.conf;, i'll get:

server {   listen *:80;   server_name someserver;    location / {     proxy_cache off;   }    location /assets {     proxy_cache mycache;   }    include my_config.conf; } 

and if try include location ^~ / {\n include my_config.conf;\n }\n i'll get:

server {   listen *:80;   server_name someserver;    location / {     proxy_cache off;   }    location /assets {     proxy_cache mycache;   }    location ^~ / {     include my_config.conf;   } } 

which causes nginx config fail duplicate location "/" in /var/opt/gitlab/nginx/conf/gitlab-http.conf:106 error.

note: my_config.conf contains add_header stuff cors, needs in location block.

you need understand how nginx processes request. location blocks not additive , must individually complete. can place statements in server block , allow individual location blocks override required (e.g. proxy_cache).

assuming of uris proxied, use this:

proxy_cache off;  location / {     proxy_pass http://foo; } location /assets {     proxy_cache mycache;     proxy_pass http://foo; } 

common statements can offloaded include file.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -