Answer the question
In order to leave comments, you need to log in
How to properly configure locations in nginx behind a balancer?
The scheme is approximately the following: There is site.ru, consisting of several applications - a site in php and java applications for a personal account. At the moment, a subdomain is configured for the cabinet and everything works - there is one location, which is directly proxied to the java application.
location / {
proxy_pass http://cabinet/;
}
# Сервера с php приложением
upstream php {
ip_hash;
server 192.168.100.20 max_fails=2 fail_timeout=360 weight=10;
server 192.168.100.30 max_fails=2 fail_timeout=360;
}
# Сервера с java приложением
upstream cabinet {
ip_hash;
server 192.168.100.101 max_fails=2 fail_timeout=360;
}
# Балансировщик, если запрашивают / - отправляет на php, если /cabinet - на java приложение
server {
listen 443 ssl;
server_name site.ru;
ssl on;
ssl_certificate /etc/nginx/ssl/site.ru.crt;
ssl_certificate_key /etc/nginx/ssl/site.ru.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
location / {
proxy_pass http://php;
proxy_redirect off;
proxy_set_header Host $host;
proxy_http_version 1.1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_next_upstream error timeout invalid_header http_500 http_503 http_504 http_502;
proxy_connect_timeout 50;
proxy_read_timeout 50;
}
location /cabinet {
proxy_pass http://cabinet;
proxy_redirect off;
proxy_set_header Host $host;
proxy_http_version 1.1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_next_upstream error timeout invalid_header http_500 http_503 http_504 http_502;
proxy_connect_timeout 50;
proxy_read_timeout 50;
}
}
}
Answer the question
In order to leave comments, you need to log in
options 2.
Or in the cabinet location, use a regulator to exclude statics so that it gets to /
Or make a /cabinet/static location and direct it to where the statics lie.
Or, in the location of the cabinet, exclude statics with a regulator so that it gets on /
location /cabinet/static {
proxy_pass http://cabinet;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question