在我的生产服务器中,我们有几个上游,它们是在带有 nginx 的反向代理后面运行的 docker 容器。其中一个容器是 mqtt 代理(mosquitto),我们用来通过 websockets 进行连接。这是我们的 nginx.conf 文件:
worker_processes 1;
events {
worker_connections 1024;
}
http {
upstream br-frontend {
server br-frontend:3000;
}
upstream br-backend {
server br-backend:5000;
}
upstream mosquitto {
server mosquitto:9001;
}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
ssl_certificate /etc/nginx/certs/server.crt;
ssl_certificate_key /etc/nginx/certs/server.key;
server {
listen 443 ssl default_server;
server_name _;
location / {
proxy_pass http://br-frontend/;
}
location /api {
proxy_pass http://br-backend;
}
location /swagger.json {
proxy_pass http://br-backend/swagger.json;
}
location /swaggerui { …Run Code Online (Sandbox Code Playgroud) 我正在设置我的第一个 HAProxy 反向代理服务器。它将成为从不同服务器在 tomcat 上运行的 HTML5 应用程序的代理。我能够让它通过 HTTP 代理出去,将所有请求重定向到 HTTPS,并实现 HSTS。但是,这样做之后我意识到它也尝试加载 websocket 连接。问题是它加载的 websocket 连接是不安全的 (ws://) 和不安全的 (wss://)。当然,Chrome(可能还有多个浏览器)会抱怨通过安全连接加载不安全的脚本。这是我得到的错误:
Connecting via WebSocket using url ws://website.domain.com:9091/webclient/
Mixed Content: The page at 'https://website.domain.com/webclient/' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'ws://website.domain.com:9091/webclient/'. This request has been blocked; this endpoint must be available over WSS.
Caught WebSocket error: SecurityError: Failed to construct 'WebSocket': An insecure WebSocket connection may not be initiated from a page loaded over HTTPS.
Run Code Online (Sandbox Code Playgroud)
所有这些都由 /webclient/script/ajaxclient.js:210 …
为了(从字面上看)在家里玩,我想获得一份 Sharepoint 的副本。我可能会找到它的用途,所以我不想要试用版。我知道有一个“免费”版本不包括 MS Office 集成等,这很好。我可能只是将它用于文档存储和其他东西。
无法让 wss:// (或 ws://) 在我的 Digital Ocean、使用 nginx 的 Ubuntu 服务器上工作,不断收到 301 重定向并且没有连接。
Websocket服务器:node + express + uws在http://localhost:3000/chat上提供服务(我已经通过在ufw中打开3000并直接与ws://连接进行了测试,工作正常。)
操作系统:Ubuntu 16.04.3 x64
这是我的 nginx 配置(我尝试了很多变体和选项,这是最简单的,老实说这似乎并不重要)
server {
listen 443 ssl; # client_wss_port
server_name www.example.org;
ssl on;
ssl_certificate /etc/letsencrypt/live/example.org/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.org/privkey.pem;
location /chat/ {
add_header locationischat 1; # this is a dummy header for debugging
proxy_pass http://localhost:3000/chat/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的 nginx 版本
nginx -v
nginx version: nginx/1.10.3 (Ubuntu)
Run Code Online (Sandbox Code Playgroud)
这是我的防火墙状态
ufw status
Status: …Run Code Online (Sandbox Code Playgroud)