Skip to content
New issue

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

WebSocket模式下静态资源的访问 #26

Closed
rxrw opened this issue Apr 10, 2018 · 2 comments
Closed

WebSocket模式下静态资源的访问 #26

rxrw opened this issue Apr 10, 2018 · 2 comments
Assignees
Labels
question Further information is requested

Comments

@rxrw
Copy link

rxrw commented Apr 10, 2018

我想请教下,在第一个配置(我认为是http)和websocket服务器下的配置有什么区别呢?
在websocket下配置nginx,无法访问public下的静态资源文件,配置内容是直接粘贴的。
而且在第一个配置下也是可以用websocket的呀

@hhxsv5
Copy link
Owner

hhxsv5 commented Apr 10, 2018

Nginx既可以写两配置 单独代理HttpWebSocket,也可以合并在一起,具体看开发者是否需要分域名独立配置。访问静态资源,直接使用try_files指令即可。

map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

upstream laravels-ws {
    server 192.168.0.1:8011 weight=5 max_fails=3 fail_timeout=30s;
    #server 192.168.0.2:5200 weight=3 max_fails=3 fail_timeout=30s;
    #server 192.168.0.3:5200 backup;
}

server {
    listen 80;
    server_name laravels-ws.com;
    root /xxxpath/laravel-s-test/public;
    access_log /xxpath/log/nginx/$server_name.access.log  main;
    location / {
        try_files $uri @laravels;
    }
    location @laravels {
	proxy_http_version 1.1;
        # proxy_connect_timeout 60s;
        # proxy_send_timeout 60s;
        # proxy_read_timeout 60s;
        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 $host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_pass http://laravels-ws;
    }
}

@hhxsv5 hhxsv5 self-assigned this Apr 10, 2018
@hhxsv5 hhxsv5 added the question Further information is requested label Apr 10, 2018
@rxrw
Copy link
Author

rxrw commented Apr 11, 2018

懂了。。但是websocket也是可以当作http代理的,懂了懂了 谢谢 还是了解的不够

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants