【问题标题】:nginx direct trafic to non domain name using IP and local namesnginx 使用 IP 和本地名称将流量重定向到非域名
【发布时间】:2019-10-30 09:00:16
【问题描述】:

在 Windows 服务器上使用 nginx 我想使用非域名名称将流量引导到不同的端口,第一个有效但第二个永远无法到达:为什么?怎么了? http://192.xxx.xxx.xxx/game: 作品 http://192.xxx.xxx.xxx/cms:永远达不到。 如果我更改名称,那么 cms 可以正常工作,而游戏永远无法到达。

server {
    listen       80;
    server_name  game;
    location /{
        proxy_pass http://localhost:4040;
        proxy_connect_timeout 60s;
        proxy_read_timeout 5400s;
        proxy_send_timeout 5400s;
        proxy_set_header host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_redirect default;
    }
location /uploads/ {
        root c:\Ebrahimi\www\appGame;
}
}

server {
    listen       80;
    server_name  cms;
    location /{
        proxy_pass http://localhost:2010;
        proxy_connect_timeout 60s;
        proxy_read_timeout 5400s;
        proxy_send_timeout 5400s;
        proxy_set_header host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_redirect default;
    }
location /uploads/ {
        root c:\Ebrahimi\www\appCms;
}
}

提到“理查德·史密斯”的新代码块:

server {
    listen       80;
    location /{
        proxy_pass http://localhost:4040;
        proxy_connect_timeout 60s;
        proxy_read_timeout 5400s;
        proxy_send_timeout 5400s;
        proxy_set_header host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_redirect default;
    }
location /uploads/ {
        root c:\Ebrahimi\www\appGame;
}
location /game {
        proxy_pass http://localhost:4040;
}
location /cms{
        proxy_pass http://localhost:2010;
}
}

【问题讨论】:

    标签: nginx server host server-name


    【解决方案1】:

    第二个server 块只能使用它的server_name 访问,例如:http://app.firouzeh-mfg.ir/

    如果您使用服务器的 IP 地址访问服务器,则请求将由第一个 server 块(或标记为 default_server 的块)处理。详情请见this document

    您的两个 URL http://192.x.x.x/gamehttp://192.x.x.x/cms(假设 IP 地址相同)访问相同的 server 块,仅相差 location

    例如:

    server {
        location /game {
            proxy_pass http://localhost:4040;
        }
        location /cms{
            proxy_pass http://localhost:2010;
        }
    }
    

    【讨论】:

    • 1- 抱歉代码块 2 中的错误,已编辑。 2-两个端口都在同一台机器上,并且通过端口指向差异项目。
    猜你喜欢
    • 2018-01-05
    • 1970-01-01
    • 2021-04-28
    • 1970-01-01
    • 2021-11-23
    • 1970-01-01
    • 2021-03-25
    • 2015-12-14
    • 2020-02-01
    相关资源
    最近更新 更多