[英]Configuring Secure Web Socket on Amazon Beanstalk
我已經在Amazon Beanstalk上部署了兩個Node.js應用程序:一個是使用React開發的前端,並使用serve運行,另一個是帶有Web套接字處理程序的MQTT代理 。 負載均衡器為nginx 1.12.1,具有以下配置(寫在后端項目的.ebextension
文件夾中):
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream websocket {
server 127.0.0.1:5000;
}
server {
listen 8080;
if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2})") {
set $year $1;
set $month $2;
set $day $3;
set $hour $4;
}
access_log /var/log/nginx/healthd/application.log.$year-$month-$day-$hour healthd;
access_log /var/log/nginx/access.log main;
large_client_header_buffers 8 32k;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass "http://127.0.0.1:3003";
proxy_redirect off;
# Socket.IO Support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass_request_headers on;
}
location /subscriptions {
proxy_pass http://websocket;
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
gzip on;
gzip_comp_level 4;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
}
前端應該能夠使用wss://mqtt_url/subscriptions
,但是無論使用wss://mqtt_url/subscriptions
配置, WebSocket is closed before the connection is established
,我總是會WebSocket is closed before the connection is established
。 此配置似乎可以解決不安全的Web套接字消耗問題。 等待連接的服務器只是一個簡單的HTTP服務器,如下所示:
const server = createServer();
server.listen(5000, '0.0.0.0', () =>
new SubscriptionServer({
execute,
subscribe,
schema,
onConnect: async (connectionParams) => {
},
}, {
server,
path: '/subscriptions',
}));
Beanstalk負載平衡的配置如下:
搜尋信息,我僅能看到選擇TCP / SSL作為協議是很好的,但是除此之外,還不清楚如何在此處配置WSS。 任何建議將不勝感激! 謝謝。
嘗試將其添加到您的訂閱位置塊
proxy_read_timeout 86400;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.