我有以下设置:
+----------------------------+ +-----------------------------+
| | | |
| | | |
| | | |
| +--------+ +--------+ | | +--------+ +-------+ |
| | | | | | | | | | | |
| | client | | nginx | | | | nginx | | server| |
| | | | | | | | | | | |
| | ws +-------> wss +-------------------------> wss +--------> ws | |
| | | | | | | | | | | |
| | | | | | | | | | | |
| +--------+ +--------+ | | +--------+ +-------+ |
| | | |
| | | |
+----------------------------+ +-----------------------------+我想通过安全的websocket将客户端与服务器连接起来。但不是直接的。客户端和服务器不知道安全性。
因此,客户端连接到:ws://localhost:6277/wstest
客户端nginx正在监听端口6277。我希望Nginx安全地将连接转发到ws.example.com/wstest。
Nginx的配置是:
server {
server_name localhost;
listen 6277;
location /wstest {
proxy_ssl_certificate /etc/nginx/ssl/client.crt;
proxy_ssl_certificate_key /etc/nginx/ssl/client.key;
proxy_ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
proxy_ssl_ciphers HIGH:!aNULL:!MD5;
proxy_ssl_session_reuse on;
resolver 127.0.0.1;
proxy_pass https://ws.example.com/wstest;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}客户端设置不起作用。客户端给出了以下错误:The HTTP response from the server [500] did not permit the HTTP upgrade to WebSocket。Nginx给我的是:"GET /ocpp/cp-1/ws HTTP/1.1" 500 193 "-" "-"。
当我绕过客户端Nginx,以便客户机只能通过服务器端Nginx直接连接(wss://ws.example.com/wstest)到服务器时,一切都正常。
服务器端的Nginx将wss转换为ws,并将连接转发到服务器。
客户端Nginx配置有什么问题吗?用Nginx将wss转换为ws没有问题。但是,是否有可能通过Nginx将ws转换为wss呢?
发布于 2017-08-09 11:54:00
一切都如我所料。我只需要设置一个不同的解析器。例如:
resolver 8.8.8.8;https://stackoverflow.com/questions/45366958
复制相似问题