Ali*_*and 7 php port websocket server
我使用Ratchet-lib/socketo.me作为我的聊天应用程序的 websocket。当我输入 localhost:8080 时,它工作得很好。
当我在线发布应用程序时,如何将我的网站设置为 wss:// ?如何打开端口 pr smthg?
这是连接代码:
$(document).ready(function(){
update_chat_history_data();
var conn = new WebSocket('wss://localhost:8080');
conn.onopen = function(e) {
console.log("Connection established!");
};
Run Code Online (Sandbox Code Playgroud)
我想更改var conn = new WebSocket('wss://localhost:8080'); var conn = new WebSocket('wss://mywebsite:port');
谢谢
如果您在生产环境中使用 nginx,并且默认情况下它具有启用 ssl 的含义 (https)。您可以对棘轮服务器进行反向代理。
upstream websocketserver {
server ratchet:8080;
}
server {
listen 443 ssl;
#you main domain configuration
location /ws/ {
proxy_pass http://websocketserver;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
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 X-Forwarded-Proto https;
proxy_read_timeout 86400; # neccessary to avoid websocket timeout disconnect
proxy_redirect off;
}
Run Code Online (Sandbox Code Playgroud)
}
您将能够使用棘轮网址,例如:wss://yourdomain.com/ws
这就是 nginx 的工作方式,但我猜 apache 或其他一些 Web 服务器也是如此。就做反向代理吧!
| 归档时间: |
|
| 查看次数: |
24980 次 |
| 最近记录: |