这是我在 Nginx 中迈出的第一步,所以任何帮助都会很棒。
我有一个小型 docker-compose 应用程序,由两个容器组成: nginx 上传
Nginx 端口 80 在主机上公开,以便可以从我们的内网访问 Nginx,如下所示:www.mytest.net 我现在将在该地址的子路径上公开 asp.net core 站点“上传”,例如: www.mytest.net/upload/
目前,我无法实现这一点,如果我尝试将其移动到上传路径,则上传的每个 URL 等都将不起作用,并且我不确定是否必须以不同方式配置 NGINX、asp.net core 或两者.
Nginx.conf 中的当前配置:
location / {
proxy_pass http://upload:80;
# The default minimum configuration required for ASP.NET Core
# See https://docs.asp.net/en/latest/publishing/linuxproduction.html?highlight=nginx#configure-a-reverse-proxy-server
proxy_cache_bypass $http_upgrade;
# Turn off changing the URL's in headers like the 'Location' HTTP header.
proxy_redirect off;
# Forwards the Host HTTP header.
proxy_set_header Host $host;
# The Kestrel web server we are forwarding requests to only speaks HTTP 1.1.
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
# Adds the 'Connection: keep-alive' HTTP header.
proxy_set_header Connection keep-alive;
}
}
就像我说的,它适用于“/”,但如果我使用“上传”,则由于 URL 不匹配,上传网站上的简单表单将不再起作用。
最佳答案
阅读 HttpContext.Request.PathBase 和名为 UsePathBase 的新扩展。这些有助于隔离应用程序根 URL,这样就不会弄乱您的路由。
关于nginx - 如何在子路径上找到 Asp.net core 站点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42596045/