【发布时间】:2020-02-13 14:55:09
【问题描述】:
我正在尝试在 Linux、Unbunt 18.04 上托管多个具有不同域的 ASP NET Core 站点,并使用 nginx 作为反向代理。
这些是步骤:
1) 在 /etc/nginx/sites-available 中创建新的 .conf 文件
2) 在 /var/www/ 中创建文件夹并上传到 .net 应用程序中
3) 为每个 .conf 文件创建新的 .service 文件
默认的 nginx .conf 不变。
.conf 文件如下所示:
server {
listen 80;
server_name domain;
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;
}
}
.service 文件如下所示:
[Unit]
Description=Event Registration Example
[Service]
WorkingDirectory=/var/www/example
ExecStart=/usr/bin/dotnet /var/www/example/example.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target
使用这种配置,即使我部署了几个站点,它们都被重定向到相同的内容。我的目标是在同一台服务器上托管多个 .net 核心应用程序。 配置应该是什么样子?
【问题讨论】:
-
您是否将新的
.conf从sites-available链接到sites-enabled然后reloadingnginx? -
是的,我将每个 .conf 文件从可用站点链接到已启用站点,为每个服务重新加载 Nginx 和 .service。
-
@S.K.你在这方面成功吗?我正在寻找类似问题stackoverflow.com/questions/66194115/… 的解决方案,并且需要一种通过代码管道线发送 nginx.conf 的方法,以便在重新发布时自动设置所有内容
-
我有一个类似的issue...有人可以帮忙吗?
标签: linux nginx asp.net-core hosting nginx-reverse-proxy