Answer the question
In order to leave comments, you need to log in
Is it possible to inherit blocks in Nginx?
Goodnight!
Is it possible to inherit locales in Nginx as includes or mixins?
For example like this:
server {
listen 80;
location / {
proxy_pass @node_proxy; # инклюд миксины
}
location /test/ {
add_header Tester '1';
proxy_pass @node_proxy; # инклюд миксины
}
location @node_proxy {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:1337;
}
}
Answer the question
In order to leave comments, you need to log in
Because you wrote it is not possible. But you can use include
File node-proxy.inc
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:1337;
server {
listen 80;
location / {
include node-proxy.inc;
}
location /test/ {
add_header Tester '1';
include node-proxy.inc;
}
}
server {
listen 80;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
location / {
proxy_pass http://127.0.0.1:1337;
}
location /test/ {
add_header Tester '1';
proxy_pass http://127.0.0.1:1337;
}
}
LOCALES IS LOCALE, THIS IS NOT LOCATION !!!!!!!!!!!!!!!!!!!!!111!!!!!!!!!!!!!!!!!!!! !!!!!!!
you can’t, nginx works in such a way that it uses only 1 location for each request. They can redirect to each other, but the request will be processed only by one, the last location. You can transfer common properties for locations to a file and include this file in all necessary locations.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question