nginx服务器多地反向代理

问题描述 投票:0回答:1

我有3个网站运行在8000,8001和8002端口,我想反向请求这个服务器。但这是行不通的

server {
listen 6102;


    location /app1 {
        proxy_pass         http://localhost:8000;
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection keep-alive;
        proxy_set_header   Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
           }
location /app2 {
        proxy_pass         http://localhost:8001;
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection keep-alive;
        proxy_set_header   Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
           }
location /app3 {
        proxy_pass         http://localhost:8002;
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection keep-alive;
        proxy_set_header   Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
           }


    }

它是我的配置文件.请告诉我,我在哪里做错了

nginx nginx-reverse-proxy nginx-location
1个回答
0
投票

我通常做的唯一一件事就是在location的末尾加上斜杠()。下面的代码段是一个有效的配置。

location /reporting/ {
       proxy_set_header X-Real-IP  $remote_addr;
       proxy_set_header X-Forwarded-For $remote_addr;
       proxy_set_header Host $host;
       proxy_pass http://127.0.0.1:8080;
}
© www.soinside.com 2019 - 2024. All rights reserved.