Answer the question
In order to leave comments, you need to log in
How to configure proxying in nginx depending on dns?
Good afternoon!
There is a proxy server (proxy-01) with such dns dev.example.com test.example.com preprod.example.com. With proxy-01, requests come to app-01/app-02 (dev/test/preprod sites here) all sites have the same locations, but different root_documents.
I know how to resolve proxying using upstreams by hanging sites on different ports.
The question is how to do it all on one port?
Thank you!
Answer the question
In order to leave comments, you need to log in
From what I understand, you need something like this:
server {
listen 80;
server_name app.example.com;
location / {
proxy_pass http://app-01/;
}
}
server {
listen 80;
server_name preprod.example.com;
location / {
proxy_pass http://app-02/;
}
}
Guys Pavel Mezhuev ky0 Alexey Ten , thank you!
Below is an example config. For each site, a separate
nginx-proxy config
upstream dev {
server 172.17.1.1;
}
server {
listen 80;
server_name dev.example.com;
client_max_body_size 32m;
server_name_in_redirect off;
gzip on;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://dev;
}
}
server {
listen 80;
server_name dev.example.com;
set $app_dir "/opt/app/dev/app";
root $app_dir;
index index.html;
client_max_body_size 32m;
access_log "/var/log/nginx/dev.access.log";
error_log "/var/log/nginx/dev.error.log";
location / {
root $app_dir;
index index.html;
add_header 'X-XSS-Protection' "1; mode=block;";
try_files $uri $uri/ /index.html =404;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question