如何在我的网站上打开 wss: 或 ws: 端口? [英] How to open wss: or ws: port on my website?

查看:703
本文介绍了如何在我的网站上打开 wss: 或 ws: 端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Ratchet-lib/socketo.me 作为我的聊天应用程序的 websocket.当我输入 localhost:8080 时,它运行良好.

I am using Ratchet-lib/socketo.me as a websocket for my chatting app. When I put localhost:8080 it works perfectly.

当我在线发布应用程序时,如何将我的 wesbite 设为 wss://?如何打开pr smthg端口?

How can I put my wesbite as wss:// when I publish the app online? How to open port pr smthg?

这是连接代码:

$(document).ready(function(){
   update_chat_history_data();
    var conn = new WebSocket('wss://localhost:8080');
conn.onopen = function(e) {
    console.log("Connection established!");
};

我想将 var conn = new WebSocket('wss://localhost:8080'); 更改为 var conn = new WebSocket('wss://mywebsite:port');

谢谢

推荐答案

如果您在生产环境中使用 nginx,并且默认情况下它具有启用 ssl 的含义 (https).比您可以对棘轮服务器进行反向代理.

If you are using nginx in your production environment and it has by default ssl enabled meaning (https). Than you can do reverse proxy to your ratchet server.

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;
    }

}

您将能够使用棘轮网址,例如:wss://yourdomain.com/ws

Than you will be able to use ratchet url like: wss://yourdomain.com/ws

这就是它在 nginx 上的工作方式,但我认为 apache 或其他一些 Web 服务器也是如此.做反向代理就行!

This is how it works with nginx but I guss is same with apache or some other web server. Just do reverse proxy!

这篇关于如何在我的网站上打开 wss: 或 ws: 端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆