Answer the question
In order to leave comments, you need to log in
Is it possible to make location dynamic in nginx?
Dear admins!
Tell me, please, is it possible in nginx to make it so that when localhost:8000 is triggered, the static is returned by the server, and when the localhost:8010 backup is triggered - by nginx.
For example, there is this config:
upstream main {
server localhost:8000;
server localhost:8010 backup;
}
server {
listen 80;
...
location / {
proxy_pass http://main;
proxy_set_header Host $http_host;
}
location /static {
alias /home/www/static;
access_log off;
}
}
upstream main {
server localhost:8000;
server localhost:8010 backup;
}
server {
listen 80;
...
location / {
proxy_pass http://main;
proxy_set_header Host $http_host;
}
if ($backup_used) {
location /static {
alias /home/www/static;
access_log off;
}
}
}
Answer the question
In order to leave comments, you need to log in
It is possible, but in your case it is not necessary.
Separate the logic into 2 different servers.
Pros:
1. Nginx will process this faster
2. Easier to read when working with configs
server {
listen 8080;
location / {
proxy_pass http://main;
proxy_set_header Host $http_host;
}
}
server {
listen 8010;
location / {
proxy_pass http://main;
proxy_set_header Host $http_host;
}
location /static {
alias /home/www/static;
access_log off;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question