nginx - 如何在子路径上找到 Asp.net core 站点

标签 nginx docker asp.net-core

这是我在 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/

相关文章:

c# - 如何修复错误 NETSDK1 找不到 project.assets.json 文件。运行 NuGet 包还原以生成此文件

linux - 我可以从 php.ini 文件更改 Nginx 变量 client_max_body_size 的值吗?

django - 如何在 uWSGI 中配置允许的 GET 参数字符数?

asp.net-core - “HttpRequest”不包含 'EnableRewind' 的定义

php - Docker、PHP PDO 和单个 MySQL 容器(无法通过容器名称连接)

java - Gradle 无法在 Mac 上运行 docker 任务

c# - 为什么 Scoped 服务会解析为同一请求的两个不同实例?

.htaccess - 除了特定 URL 之外的所有页面上的 nginx 基本身份验证,它遵循

django - Gunicorn 无法运行服务器

shell - 在 dockerfile 中插入条件 RUN 语句