I've following server blocks in my nginx configuration:
server {
listen 80; #default_server;
listen [::]:80; #default_server;
client_max_body_size 20M;
client_header_timeout 600;
client_body_timeout 600;
keepalive_timeout 600;
server_name example1-proxy.in;
location / {
proxy_pass http://example1.in;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Forwarded $proxy_add_forwarded;
proxy_set_header X-Forwarded-For "";
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
}
}
server {
listen 80; #default_server;
listen [::]:80; #default_server;
client_max_body_size 20M;
client_header_timeout 600;
client_body_timeout 600;
keepalive_timeout 600;
server_name example2-proxy.in;
location / {
proxy_pass http://example2.in;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Forwarded $proxy_add_forwarded;
proxy_set_header X-Forwarded-For "";
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
}
}
I want to configure the example1-proxy and example2-proxy as a proxy pass in another nginx configuration, so I did the following:
server {
listen 80; #default_server;
listen [::]:80; #default_server;
client_max_body_size 20M;
client_header_timeout 600;
client_body_timeout 600;
keepalive_timeout 600;
server_name example5.in;
location /temp1/ {
proxy_pass http://example1-proxy.in;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Forwarded $proxy_add_forwarded;
proxy_set_header X-Forwarded-For "";
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
}
location /temp2/ {
proxy_pass http://example2-proxy.in;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Forwarded $proxy_add_forwarded;
proxy_set_header X-Forwarded-For "";
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
}
}
CodePudding user response:
solved it,actually in the second nginx configuration:
location /temp1/ {
proxy_pass http://example1-proxy.in;
proxy_set_header Host $host;
the $host should be replaced by the example1-proxy.in, only then this server block will be active. so correct config will be :
location /temp1/ {
proxy_pass http://example1-proxy.in;
proxy_set_header Host example1-proxy.in;

