• Почему не работает socket.io на nginx?

    asvechkar
    @asvechkar Автор вопроса
    ruby on rails, angular, MEAN, postgres
    Решил проблему, надуюсь кому то еще пригодится.
    Мой конфигурационный файл для сайта:
    upstream web-portal {
        server 127.0.0.1:5050;
        keepalive 15;
    }
    
    server {
        listen 80;
        server_name demo.portal.ru;
        root /var/projects/web.portal/current/public;
        access_log /var/log/nginx/web-portal.log;
        error_log /var/log/nginx/web-portal.error.log;
    
        location / {
            proxy_pass http://web-portal;
    
            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;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    
        location ^~ /socket {
               rewrite  ^/socket/(.*)  /$1 break; #used to send request to base url
               proxy_pass http://web-portal;
               proxy_redirect off;
               proxy_pass_request_headers on;
               proxy_set_header X-Real-IP $remote_addr;
               proxy_set_header Host $http_host;
               proxy_set_header X-NginX-Proxy true;
               proxy_set_header X-Forwarded-Host $host;
               proxy_set_header X-Forwarded-Server $host;
               proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
               proxy_http_version 1.1;
               proxy_set_header Upgrade $http_upgrade;
               proxy_set_header Connection "upgrade";
               proxy_set_header Host $host;
    
        }
    
        location ~* \.(?:jpg|jpeg|gif|png|css|js)$ {
            expires 30d;
        }
    }
    Ответ написан
    Комментировать