我有 2 個服務在 Azure 應用服務的 Docker 容器中運行。我想從每個服務中公開一些 API,并且一個服務也使用套接字。在本地使用 Docker 容器(無 SSL)時一切正常,但在使用 Azure 應用程式服務時卻不行:如果我轉到我的服務的前端,例如https://myservicename.azurewebsites.net,那么創建時會出錯一個 WebSocket 連接。DevTools 說它正在嘗試連接到“wss://myservicename.azurewebsites.net/stream”。
它們都是 Python 服務。一個是 Flask 服務,另一個使用 Streamlit。
nginx.conf:
server {
listen 8502;
# One service runs on port 5000 (Python Flask).
# It just uses HTTP requests.
location /api/run {
proxy_pass http://localhost:5000/run;
}
location /api/results {
proxy_pass http://localhost:5000/results;
}
# The other service runs on port 8501 (Python Streamlit).
# It uses HTTP requests, has a front end web page, and uses WebSockets.
location / {
proxy_pass http://localhost:8501;
# Get web sockets to work too:
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
Dockerfile:
FROM mcr.microsoft.com/mirror/docker/library/python:3.9-slim
# Set up some environment variables.
...
EXPOSE 8502
RUN apt --yes update && apt --yes install curl nginx
COPY nginx.conf /etc/nginx/conf.d/my_app.conf
# Install some dependencies.
...
# Start nginx and my 2 services.
CMD nginx && \
(poetry run python ./back_end/main.py & \
poetry run streamlit run ./dashboard/dashboard.py)
我應該更改哪些內容才能使安全的 WebSockets 在 Azure 應用服務中作業?我已經看到有關在 nginx 配置中配置 SSL 和證書的資訊,但我認為我不必擔心這一點,因為 Azure 應用服務會為我的應用處理證書內容。
uj5u.com熱心網友回復:
從websocket-nginx檔案中,您似乎nginx.conf缺少 Host 標頭
proxy_set_header Host $host;
我對標題缺少大寫的經驗有好有壞,因此請嘗試使用大寫“U”進行“升級”
proxy_set_header Connection "Upgrade";
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/492387.html
上一篇:AlpineNginxinstall找不到`upload_progress`指令,盡管它被編譯成二進制檔案
下一篇:我的Nginx服務正在運行,如果我運行curllocalhost它會顯示登錄頁面HTML。但無法從ec2IP訪問
