我一直在努力使用 nginx 和主管在 EC2 ubuntu 实例上运行几个 asp.net 核心 web 应用程序。我成功地一次运行一个应用程序,只需在我的 nginx 设置中交换我的端口并重新加载,我就可以在 5000 和 5001 上运行的正在运行的 .netcore 应用程序之间进行交换。我似乎无法弄清楚 nginx 设置使它们同时存在在路径上工作,即:主机名/应用程序1,主机名/应用程序2。
这是我的 Nginx 配置。谁能指出我做错了什么?我的主管正在运行这两个应用程序,我可以通过查看日志并更改默认位置“/”中的端口来验证这一点。
server {
listen 80 default_server;
listen [::]:80 default_server;
# 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;
# }
location /app1 {
rewrite ^/app1(.*) /$1 break;
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;
}
location /app2{
rewrite ^/app2(.*) /$1 break;
proxy_pass http://localhost:5001;
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;
}
}
我没有简单的默认路线,因为我还没有任何东西可以放在那里。
最佳答案
看起来解决方案是在位置和代理通行证上添加斜杠
server {
listen 80 default_server;
listen [::]:80 default_server;
# 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;
# }
location /app1/ {
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;
}
location /app2/ {
proxy_pass http://localhost:5001/;
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;
}
}
关于nginx - nginx上的asp.net核心多个应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45745503/