【问题标题】:How to redirect NGINX to a websocket如何将 NGINX 重定向到 websocket
【发布时间】:2018-09-21 07:53:33
【问题描述】:
  1. NGINX - 位于 10.10.10.1
  2. LAMP - 坐在 172.168.1.1 上,有 phpwebsockets。它在 http://172.168.1.1:8080 上侦听,并且在 http://172.168.1.1:8080/ws 上有 ws 文件夹

Nginx 应该以这种方式转发请求。

 NGINX                                 --->      LAMP Websocket

http://10.10.10.1/randomstring/ --> https://10.10.10.1/randomstring/ --> http://172.168.1.1:8080

当前的 /conf.d/internal.conf nginx 配置文件是

server {
    listen         80;
    server_name    172.168.1.1;
    return         301 https://$host$request_uri; #redirect to self with https
    }
server {
    listen          443 ssl;
    server_name     172.168.1.1;
    root           /var/www/nginx/;
    index          index.html;
    proxy_cache one;
    location /ws {
        proxy_pass http://172.168.1.1:8080;
        # this magic is needed for WebSocket
        proxy_http_version  1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
    }
    location / {
        proxy_pass http://172.168.1.1:8080;
    }
}

我无法转发到 /randomstring ,它适用于没有 'randomstring' 的情况。

【问题讨论】:

  • 对任何人有帮助吗?

标签: nginx websocket nginx-location nginx-reverse-proxy


【解决方案1】:

请在proxy_pass末尾加“/”

proxy_pass http://172.168.1.1:8080/;

【讨论】:

  • 但是在哪里输入随机字符串路径呢?
猜你喜欢
  • 2022-01-11
  • 2017-12-30
  • 1970-01-01
  • 2022-08-14
  • 1970-01-01
  • 2015-10-19
  • 2017-09-24
  • 2011-04-23
相关资源
最近更新 更多