Answer the question
In order to leave comments, you need to log in
How to configure nginx proxy_pass to internal servers by location?
There is a server with nginx (nginx/1.16.1) demo.test.local (192.168.220.11) and several servers with apache behind it (192.168.222.30, 192.168.222.32, 192.168.222.35). The task was set when calling https://demo.test.local/ <numeric_identifier> to redirect the request to apache, the server is selected depending on the <numeric_identifier>.
So far, for the test, I work with one server ip=192.168.222.35, <numeric_id>=123
nginx configuration
server {
listen 443;
server_name demo.test.local;
access_log /var/log/nginx/t_access.log test;
error_log /var/log/nginx/t_error.log info;
ssl_certificate /etc/pki/tls/certs/test.local.crt;
ssl_certificate_key /etc/pki/tls/private/test.key;
location / {
# try_files $uri @gm;
}
location /123/ {
proxy_pass https://192.168.222.35/;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect / /123/;
}
location @gm {
proxy_pass https://192.168.222.35;
}
}
[28/Oct/2021:17:30:39 +0300] "302" "HOST=demo.test.local proxy-host=192.168.222.35 uri=/123/ query=- referrer=-
---------------------------------
[28/Oct/2021:17:30:39 +0300] "200" "HOST=demo.test.local proxy-host=192.168.222.35 uri=/123/Account/LogOn query=ReturnUrl=%2f referrer=-
---------------------------------
[28/Oct/2021:17:30:39 +0300] "404" "HOST=demo.test.local proxy-host=- uri=/front/dist/logon.vendor.434d9aea5bd43fa26608.css query=- referrer=-
---------------------------------
[28/Oct/2021:17:30:39 +0300] "404" "HOST=demo.test.local proxy-host=- uri=/front/dist/logon.dc155e55d90848a71888.css query=- referrer=-
---------------------------------
[28/Oct/2021:17:30:39 +0300] "404" "HOST=demo.test.local proxy-host=- uri=/front/dist/logon.vendor.434d9aea5bd43fa26608.js query=- referrer=-
---------------------------------
[28/Oct/2021:17:30:39 +0300] "404" "HOST=demo.test.local proxy-host=- uri=/front/dist/logon.dc155e55d90848a71888.js query=- referrer=-
Answer the question
In order to leave comments, you need to log in
Set the server to 192.168.222.35 so that it prefixes /123/
links to js, css, images, etc. How exactly to do this is highly dependent on the server.
But usually it's easier not to bother with this, but to raise subdomains.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question