【发布时间】:2022-02-10 13:54:10
【问题描述】:
操作系统:Ubuntu 18.04,Nginx 版本:1.14.0,Asp.net 版本:core 3.1
长话短说:
- 无法从 linux 机器外部访问端口 5001。但可以打到里面。
- Nginx 正在传递请求,但它没有访问 Web 应用程序。
- 同一服务器下同一 nginx 下的另一个网站正在运行。
部署后它停止工作。当我访问https://example.com 时,Nginx 会发出 307 重定向到https://www.example.com:5001/。我的浏览器无法访问它,说“看起来www.mywsite.com 关闭了连接”。部署只发生了变化
wget https://localhost:5001 --no-check-certificate
因此,Web 应用程序似乎会响应向端口 5001 发出的请求。但不知何故,请求并没有从 Nginx 发送到应用程序。
在同一台服务器上托管的另一个网站(侦听端口 5050)与 Nginx 几乎相同的配置在浏览器上运行良好(接收代码 200 而不是 307)。
我已经重新启动了网络服务器,重新启动了 dotnet Web 应用程序,重新加载了 nginx。没有任何效果。
这里是“mysite”的 nginx 配置:
server {
large_client_header_buffers 4 32k;
server_name example.com www.example.com;
location / {
proxy_pass http://mysite;
proxy_http_version 1.1;
root /var/www/mysite/;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded_Proto $scheme;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
upstream mysite{
zone dotnet 64k;
server 127.0.0.1:5000;
}
server {
if ($host = www.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
large_client_header_buffers 4 32k;
listen *:80;
server_name example.com www.example.com;
return 404; # managed by Certbot
}
当我通过 dotnet 列出所有监听服务时,有趣的是工作网站只监听 5050:
tcp 0 0 127.0.0.1:5050 0.0.0.0:* LISTEN 1654/dotnet
tcp 0 0 127.0.0.1:5000 0.0.0.0:* LISTEN 5510/dotnet
tcp 0 0 127.0.0.1:5001 0.0.0.0:* LISTEN 5510/dotnet
tcp 0 0 127.0.0.1:40678 127.0.0.1:3306 ESTABLISHED 1654/dotnet
tcp6 0 0 ::1:5050 :::* LISTEN 1654/dotnet
tcp6 0 0 ::1:5000 :::* LISTEN 5510/dotnet
tcp6 0 0 ::1:5001 :::* LISTEN 5510/dotnet
来自 nginx access.log 的尾部:
(我的 IPv4 地址) - - [05/May/2021:15:37:55 -0400] "GET / HTTP/1.1" 307 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36 Edg/90.0.818.46"
来自 nginx error.log 的尾部(我确实找到了几个小时前的一些条目,但最近的失败并没有创建条目):
2021/05/05 12:03:11 [错误] 5481#5481: *187 过早上游 从上游读取响应标头时关闭连接,客户端: {我的 IPv4 地址} 26,服务器:example.com,请求:“GET / HTTP/1.1”,上游:“http://127.0.0.1:5001/”,主机:“example.com”
感谢任何帮助。 谢谢。
【问题讨论】:
-
能否请您分享错误的尾部和访问日志。
-
@PouyaEsmaeili 我已经添加了日志条目。谢谢你的提问。
-
你说5001端口正在监听,但是我在你的nginx conf中找不到相关配置。你确定 5001 端口在监听吗?
-
最后的访问日志告诉请求重定向成功,但是重定向的请求没有被记录。我希望在显示的日志之后看到该请求。
标签: asp.net-core ubuntu nginx