我nginx.conf
在本地按预期工作,没有错误,但是当移动到这个应用服务环境时,我得到了下面列出的错误。
我正在使用Web App for Containers 中的 Azure App Service 多容器(预览版)应用程序开发基于 TypeScript 的 React 应用程序,但遇到了 NGINX 的一些问题。我得到的主要错误是一些错误日志,当我尝试运行应用服务时会这样说:
- “连接()失败(111:连接被拒绝)”
- “连接到上游时没有实时上游”
我的WEBSITES_PORT
下App Service > Settings > Configuration
设置为80
. 我也尝试将其设置为80:80
. 在这两种情况下,我都会在下面得到相同的错误日志。WEBSITES_PORT
在容器设置文件的服务列表中设置3001
和删除 nginx 会导致应用服务部署成功。
让我知道除了下面的文件之外,我是否可以提供其他文件。
我的容器设置App Service > Settings > Container Settings
指向我的私有 Azure 容器注册表,该注册表存储了我的所有应用程序映像。该结构与我用于本地部署的 docker compose 文件非常相似。
version: '3.3'
services:
mysite:
image: "reactapp.azurecr.io/my_site_img"
ports:
- "3001:3001"
nginx:
image: "reactapp.azurecr.io/nginx"
ports:
- "80:80"
一个nginx.conf
控制我的 nginx 映像中的路由。
upstream my_site_proxy {
server localhost:3001;
}
server {
listen 0.0.0.0:80;
server_name localhost;
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://my_site_proxy/;
proxy_redirect off;
}
}
当我尝试使用上述配置运行我的 Azure 应用服务时生成的错误日志文件。
2020-07-13T01:22:52.929149550Z 2020/07/13 01:22:52 [error] 27#27: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.16.7.1, server: localhost, request: "GET /robots1234.txt HTTP/1.1", upstream: "http://127.0.0.1:3001/robots1234.txt", host: "127.0.0.1:4548"
2020-07-13T01:22:52.929653182Z 2020/07/13 01:22:52 [warn] 27#27: *1 upstream server temporarily disabled while connecting to upstream, client: 172.16.7.1, server: localhost, request: "GET /robots1234.txt HTTP/1.1", upstream: "http://127.0.0.1:3001/robots1234.txt", host: "127.0.0.1:4548"
2020-07-13T01:22:52.930048306Z 2020/07/13 01:22:52 [error] 27#27: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.16.7.1, server: localhost, request: "GET /robots1234.txt HTTP/1.1", upstream: "http://127.0.0.1:3001/robots1234.txt", host: "127.0.0.1:4548"
2020-07-13T01:22:52.930060507Z 2020/07/13 01:22:52 [warn] 27#27: *1 upstream server temporarily disabled while connecting to upstream, client: 172.16.7.1, server: localhost, request: "GET /robots1234.txt HTTP/1.1", upstream: "http://127.0.0.1:3001/robots1234.txt", host: "127.0.0.1:4548"
2020-07-13T01:22:52.936363702Z 172.16.7.1 - - [13/Jul/2020:01:22:52 +0000] "GET /robots1234.txt HTTP/1.1" 502 157 "-" "-" "-"
2020-07-13T01:22:53.004840493Z 2020/07/13 01:22:53 [error] 27#27: *1 no live upstreams while connecting to upstream, client: 172.16.7.1, server: localhost, request: "GET /robots933456.txt HTTP/1.1", upstream: "http://my_site_proxy /robots933456.txt", host: "127.0.0.1:4548"
2020-07-13T01:22:53.005790052Z 172.16.7.1 - - [13/Jul/2020:01:22:53 +0000] "GET /robots933456.txt HTTP/1.1" 502 157 "-" "-" "-"
2020-07-13T01:22:53.024544427Z 2020/07/13 01:22:53 [error] 27#27: *4 no live upstreams while connecting to upstream, client: 172.16.7.1, server: localhost, request: "GET / HTTP/1.1", upstream: "http://my_site_proxy /", host: "mysite.azurewebsites.net", referrer: "https://portal.azure.com/"
2020-07-13T01:22:53.025501687Z 172.16.7.1 - - [13/Jul/2020:01:22:53 +0000] "GET / HTTP/1.1" 502 559 "https://portal.azure.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36" "198.8.81.196:62138"
2020-07-13T01:22:53.152345935Z 2020/07/13 01:22:53 [error] 27#27: *5 no live upstreams while connecting to upstream, client: 172.16.7.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", upstream: "http://my_site_proxy /favicon.ico", host: "mysite.azurewebsites.net", referrer: "https://mysite.azurewebsites.net/"
2020-07-13T01:22:53.153395901Z 172.16.7.1 - - [13/Jul/2020:01:22:53 +0000] "GET /favicon.ico HTTP/1.1" 502 559 "https://mysite.azurewebsites.net/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36" "198.8.81.196:62138"