Configure Nginx with proxy_pass
107,678
Give this a try...
server {
listen 80;
server_name dev.int.com;
access_log off;
location / {
proxy_pass http://IP:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-for $remote_addr;
port_in_redirect off;
proxy_redirect http://IP:8080/jira /;
proxy_connect_timeout 300;
}
location ~ ^/stash {
proxy_pass http://IP:7990;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-for $remote_addr;
port_in_redirect off;
proxy_redirect http://IP:7990/ /stash;
proxy_connect_timeout 300;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/nginx/html;
}
}
Author by
bear
Updated on July 09, 2022Comments
-
bear almost 2 years
I'm trying to configure Nginx to proxy stuff on a subdomain: dev.int.com
I want dev.int.com to be proxied to IP:8080, and dev.int.com/stash to be proxied to IP:7990
Here's my current config file
server { listen 80; server_name dev.int.com; access_log off; location / { proxy_pass http://IP:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-for $remote_addr; port_in_redirect off; proxy_redirect http://IP:8080/jira /; proxy_connect_timeout 300; location ~ ^/stash { proxy_pass http://IP:7990; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-for $remote_addr; port_in_redirect off; proxy_redirect http://IP:7990/ /stash; proxy_connect_timeout 300; } } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/local/nginx/html; } }
However, /stash redirects are going to /. What am I doing wrong?
-
bear over 11 yearsHi, still redirecting to / instead of /stash
-
Andrew Kloos over 11 yearsHey - Ok check out this guy's conf file. he's got two server entries which could help your situation out. stackoverflow.com/questions/1174554/…
-
Madbreaks almost 6 yearsThis answer could be improved with context/explanation. Code blocks alone are rarely sufficient.
-
Root0x almost 5 yearsThe reason that this answer is redirecting to / insteal of /stash is because the location / block is above the location ~ ^/stash block