Configure Nginx with proxy_pass

前端 未结 2 380
隐瞒了意图╮
隐瞒了意图╮ 2020-12-08 03:10

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

相关标签:
2条回答
  • 2020-12-08 03:55

    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;
        }
    }
    
    0 讨论(0)
  • 2020-12-08 03:58

    Nginx prefers prefix-based location matches (not involving regular expression), that's why in your code block, /stash redirects are going to /.

    The algorithm used by Nginx to select which location to use is described thoroughly here: https://www.digitalocean.com/community/tutorials/understanding-nginx-server-and-location-block-selection-algorithms#matching-location-blocks

    0 讨论(0)
提交回复
热议问题