2015-09-07 3 views
0

Я пытаюсь заставить nginx обслуживать веб-порты из каталога на порту 80, а не корневого домена на порт, который прослушивает node.js.Как заставить nginx обслуживать websockets из каталога?

Подключение непосредственно к порту работает, но попытка подключения через каталог, указанный в конфигурации nginx. Я продолжаю получать код 502 из браузера и 301 при использовании curl.

Моего Nginx сервер конфигурация выглядит следующим образом:

server { 
    listen 80 default_server; 
    listen [::]:80 default_server ipv6only=on; 

    root /www; 
    index index.html index.htm index.php; 

    server_name my_ip; 

    location /smth-chat/ { 
     proxy_set_header X-Real-IP $remote_addr; 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     proxy_set_header Host $http_host; 
     proxy_set_header X-NginX-Proxy true; 

     proxy_pass http://127.0.0.1:3335; 
     proxy_redirect off; 

     proxy_http_version 1.1; 
     proxy_set_header Upgrade $http_upgrade; 
     proxy_set_header Connection "upgrade"; 
    } 

    location/{ 
     try_files $uri $uri/ =404; 
    } 

    location /something-something/ { 
     try_files $uri $uri/ /something-something/index.php?q=$uri&$args; 
    } 

    location ~ \.php$ { 
     fastcgi_split_path_info ^(.+\.php)(/.+)$; 

     try_files $uri =404; 
     fastcgi_pass unix:/var/run/php5-fpm.sock; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     include fastcgi_params; 
    } 
} 

my_ip/что-то с чем-то/чат служит HTML-страницу с Socket.io чатом, который пытается подключиться к my_ip/чего-л-чат через WebSocket (форсированный в socket.io).

Запись в моем Nginx error.log выглядит следующим образом:

2015/09/07 17:42:15 [error] 19277#0: *264 upstream prematurely closed connection while reading response header from upstream, client: some_ip, server: my_ip, request: "GET /smth-chat/?EIO=3&transport=websocket HTTP/1.1", upstream: "http://127.0.0.1:3335/smth-chat/?EIO=3&transport=websocket", host: "my_ip" 

стороне клиента socket.io инициируют:

var socket = io('http://my_ip', { 
    path: '/smth-chat', 
    transports: ['websocket'] 
    }); 

Что я делаю неправильно?

+0

Пожалуйста, проверьте его http://stackoverflow.com/questions/30450904/how-to-pass-nginx-proxy-url-for-socket/30461535#30461535, может быть, это может помочь вам –

ответ

0

Ваша проблема заключается в том, что ваша конфигурация nginx позволяет подключаться к /en, она должна разрешать только /en/. Проверь это.

Correct proxy path in nginx.conf

Смежные вопросы