【发布时间】:2021-06-01 05:35:17
【问题描述】:
我想将我在 Windows 上工作的项目转移到 Unix 机器上运行。
使用 Nginx 在 Debian 9 上运行的机器。
这个项目在带有 IIS 的 Windows 上运行得非常好。
我已按照here 上的所有说明创建了一个服务,以便在机器启动时运行此服务,并使用 Nginx 配置代理从我要使用的端口到端口 5000 的连接。
当我启动运行 Dotnet Myddl.dll 的应用程序时,它会启动并说它只在侦听端口 5000。
然后当我尝试访问它时,我会看到一个警告。
警告:Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware[3] 无法确定重定向的 HTTPS 端口。
我知道这与我的应用重定向到 HTTPS 并且不知道将其重定向到哪里有关,但我该如何解决这个问题?
我的服务
[Unit]
Description=Myapp API
[Service]
WorkingDirectory=/var/www/myapp/publish
ExecStart=/usr/bin/dotnet /var/www/myapp/publish/myapp.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target
server {
listen 6969;
server_name mysite.net *.mysite.net;
location / {
proxy_pass http://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;
}
}
编辑:
我一直在尝试解决这个问题,但仍然无法解决。当我在 unix 机器上启动应用程序时,我得到以下信息
root@myhost:/var/www/myapp/publish# dotnet Myapp.dll info: Microsoft.Hosting.Lifetime[0] Now listening on: localhost:5000 info: Microsoft.Hosting.Lifetime[0] Application started. Press Ctrl+C to shut down. info: Microsoft.Hosting.Lifetime[0] Hosting environment: Production info: Microsoft.Hosting.Lifetime[0] Content root path: /var/www/myapp/publish
显然它缺少 https 选项,我不知道为什么。
编辑2: 我已经将应用程序发布为 Linux-x64 的自包含应用程序,现在我没有收到警告说它无法确定 https 端口,在我的浏览器上,当我访问时我被重定向到 https://mydomain:5001它在 http://mydomain:6969 我仍然没有让应用程序在 Unix 上监听 https,只是在 Windows 上。
编辑3: 注意到如果我去我的端点之一,例如http://IP:6969/api/users 我收到 500 响应。
编辑4: 当我在本地加载我的应用程序时,我直接进入了招摇页面,例如 /swagger/index.html,由于某种原因,我的 API 在为 Linux 编译时不接受此 URL 并返回 404,但如果我到达我的一个端点,例如/api/users,它确实返回了我期望的数据。
【问题讨论】: