We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
# nginx.conf/http/ server { listen 80; # 静态资源访问路径 location ~* \.(html|js|css|png|jpg|jpeg|htm|ico|gif|ttf|woff)$ { root /home/xxxx; } # 默认页 location / { root html; index index.html; # 配合browserHistory模式时使用 try_files $uri $uri/ /index.html; } # 代理请求API location /api { proxy_pass http://api.liuyidi.com; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; } # 代理全局除去静态资源以外的资源 location ~ .*$ { proxy_pass http://api.liuyidi.com; proxy_pass_header Server; proxy_set_header X-Real_IP $remote_addr; proxy_set_header X-Scheme $scheme; proxy_http_version 1.1; proxy_connect_timeout 4s; proxy_read_timeout 600s; proxy_send_timeout 12s; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; } }
前端配置
function createWebSocket(basePath,serviceName){ var websocket; if ('WebSocket' in window) { websocket = new WebSocket("ws://"+basePath+"/"+serviceName); } else if ('MozWebSocket' in window) { websocket = new MozWebSocket("ws://"+basePath+"/"+serviceName); } else { websocket = new SockJS("http://"+basePath+"/sockjs/"+serviceName); } websocket.onopen = function (e) { } websocket.onmessage= function (e) { } websocket.onerror= function (e) { } websocket.onclose= function (e) { } }
服务端java配置
webSocketHandlerRegistry .addHandler(goodsWebsocketHandler(),"/websocket.do") .addInterceptors(new HandshakInterceptor()) .setAllowedOrigins("*"); // 不使用sockjs webSocketHandlerRegistry.addHandler(goodsWebsocketHandler(),"/sockjs/websocket.do").addInterceptors(new HandshakInterceptor()).withSockJS();
nginx配置
# nginx.conf/http/ map $http_upgrade $connection_upgrade { default upgrade; '' close; } server { location / { proxy_pass http://www.liuyidi.com; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_set_header Origin ''; } }
setAllowedOrigins("*")
proxy_set_header Origin ''
# gzip配置 gzip on; gzip_min_length 1k; gzip_comp_level 9; gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; gzip_vary on; gzip_disable "MSIE [1-6]\.";
wss://example.com:8088/websocket
ws 基于http下的一种协议,默认的服务端口是80. wss 基于https下的一种协议,默认的服务端口是433,如果使用wss则也需要使用433的端口号而不是80
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Nginx 配置采坑总结
1. nginx配置前后端分离
2. nginx location匹配规则
3. nginx如何支持websocket
前端配置
服务端java配置
nginx配置
4. nginx反向代理websocket报403错误问题
setAllowedOrigins("*")
proxy_set_header Origin ''
5. nginx开启gzip加速
6. websocket支持https出现ERR_SSL_PROTOCOL_ERROR的原因
ws 基于http下的一种协议,默认的服务端口是80.
wss 基于https下的一种协议,默认的服务端口是433,如果使用wss则也需要使用433的端口号而不是80
The text was updated successfully, but these errors were encountered: