nginx配置支持websocket

xiaoxiao2021-02-28  48

找到nginx.conf

把这两行配置加上就可以了

proxy_set_header Upgrade $http_upgrade;

proxy_set_header Connection "upgrade";

放在自己server里的location ~ / {

}里面。

例如

server {                         listen       80;                         server_name  xxx.mmm.com;                         charset utf-8;                         index /index.jsp;                                              location ~* ^.+\.(log|jpg|jpeg|gif|png|ico|html|cfm|cfc|afp|asp|lasso|pl|py|txt|fla|swf|zip)$ {                                 root /data/project/erp-crm-tj-web/code;                                 expires 1d;                         }                         location ~* ^.+\.(js|css|less)$ {                                 root /data/project/erp-crm-tj-web/code;                                 expires 2h;                         }                         location ~ / {                                 proxy_pass http://121.153.197.176:13982;                                 proxy_redirect              off;                                 proxy_set_header            Host $host;                                 proxy_set_header            X-Real-IP $remote_addr;                                 proxy_set_header            X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Upgrade $http_upgrade;                                 proxy_set_header Connection "upgrade";                                 client_max_body_size 10m;                                 client_body_buffer_size 128k;                                 proxy_connect_timeout 90;                                 proxy_send_timeout 120;                                 proxy_read_timeout 120;                                 proxy_buffer_size 4k;                                 proxy_buffers 4 32k;                                 proxy_busy_buffers_size 64k;                                 proxy_temp_file_write_size 64k;                                 add_header Pragma "no-cache";                                 add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";                         }                 }

转载请注明原文地址: https://www.6miu.com/read-77232.html

最新回复(0)