我正在测试将net core应用程序部署到运行Ubuntu 18.04和Nginx 1.14的Digitalocean droplet上。为了进行测试,我使用了“dotnet new”提供的模板。
使用dotnet new web和dotnet new mvc应用程序工作正常。我可以通过浏览器访问它们。我在使用dotnet new webapi应用程序方面遇到了问题。无论我如何尝试访问它,最终都会得到一个ERR_CONNECTION_REFUSED响应。
我设置droplet的步骤简述如下:
wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo add-apt-repository universe
sudo apt-get install apt-transport-https
sudo apt-get update
sudo apt-get install dotnet-sdk-2.2
sudo apt install nginx sudo ufw allow 'Nginx HTTP'
/etc/nginx/sites-available/default内容:
server {
listen 80;
location / {
proxy_pass http://127.0.0.1:5000; #also tried localhost:5000
proxy_http_version 1.1;
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;
}
}
curl的结果(IP地址有意留空)
curl -I -X GET http://123.123.123.123/api/values
HTTP/1.1 307 Temporary Redirect
Server: nginx/1.14.0 (Ubuntu)
Date: Sun, 19 May 2019 00:32:21 GMT
Content-Length: 0
Connection: keep-alive
Location: https://123.123.123.123:5001/api/values
我的Nginx日志出现以下错误,我已经通过谷歌搜索但没有找到解决方法:
2019/05/19 00:03:06 [error] 3632#3632: *4 connect() failed (111: Connection refused) while connecting to upstream, client: 12.123.12.123, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "123.123.123.117"
回复 @Oliver 的问题,以下是 netstat -ntlp 的输出结果:
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3527/nginx: master
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 605/systemd-resolve
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 946/sshd
tcp6 0 0 :::22 :::* LISTEN 946/sshd
你有什么建议是我可能忽视的吗?
谢谢!
netstat -nltp
的输出是什么? - Oliver