通過域名訪問websocket,nginx配置websocket


nginx 配置文件如下:

server
{
    listen 80;
    server_name api.xxx.com;
    index index.php index.html index.htm default.php default.htm default.html;
    root /www/wwwroot/dev.xxx/public;
    
    #SSL-START SSL相關配置,請勿刪除或修改下一行帶注釋的404規則
    #error_page 404/404.html;
    #SSL-END
    
    #ERROR-PAGE-START  錯誤頁配置,可以注釋、刪除或修改
    #error_page 404 /404.html;
    #error_page 502 /502.html;
    #ERROR-PAGE-END
    
    #PHP-INFO-START  PHP引用配置,可以注釋或修改
    include enable-php-74.conf;
    #PHP-INFO-END
    
    #REWRITE-START URL重寫規則引用,修改后將導致面板設置的偽靜態規則失效
    include /www/server/panel/vhost/rewrite/api.xxx.com.conf;
    #REWRITE-END
    
    #禁止訪問的文件或目錄
    location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
    {
        return 404;
    }
    
    #一鍵申請SSL證書驗證目錄相關設置
    location ~ \.well-known{
        allow all;
    }
    
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires      30d;
        error_log off;
        access_log /dev/null;
    }
    
    location ~ .*\.(js|css)?$
    {
        expires      12h;
        error_log off;
        access_log /dev/null; 
    }
   
   #websocket
    location /ws {
        proxy_http_version 1.1;
        
        proxy_set_header Connection "";
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Real-PORT $remote_port;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header Scheme $scheme;
        proxy_set_header Server-Protocol $server_protocol;
        proxy_set_header Server-Name $server_name;
        proxy_set_header Server-Addr $server_addr;
        proxy_set_header Server-Port $server_port;
        
        proxy_set_header Upgrade $http_upgrade;  
        proxy_set_header Connection "Upgrade";
		#轉發的端口
        proxy_pass http://127.0.0.1:9512;    
    }    
    access_log  /www/wwwlogs/api.xxx.com.log;
    error_log  /www/wwwlogs/api.xxx.com.error.log;
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM