【问题标题】:NGINX unexpected behaviour with location directive and proxy_pass位置指令和 proxy_pass 的 NGINX 意外行为
【发布时间】:2017-07-25 08:05:31
【问题描述】:

我有一个 NGINX 配置文件,通过开发服务器为网站提供静态文件服务。

静态 -> http://localhost:8080

开发网络服务器 -> http://localhost:8080/dev

还有其他几个服务我绑定到不同的位置指令。

这是配置文件的片段。

...
upstream qgis {
   server qgis-spcluster_server:80;
}
...    
server {
    listen       8080;
    server_name  localhost;

location / {
    root   /usr/share/nginx/html/build;
    index  index.html index.htm;

    auth_basic "Zugangskontrolle";
    auth_basic_user_file /etc/nginx/.htpasswd;
}

location /dev/ {
    proxy_pass http://web_app/;

    auth_basic "Zugangskontrolle";
    auth_basic_user_file /etc/nginx/.htpasswd;
}

location /static/ {
    proxy_pass http://web_app/static/;
}

location /qgis/ {
    proxy_pass http://qgis/;
}

location /apex/ {
    proxy_pass http://apex/apex/;
    auth_basic "off";
}

...

在我打开 URL 以获取静态文件之前,一切都按预期工作。之后,所有其他 URL 都指向静态文件。

对我来说,一切看起来都很好,但确实有些问题。

Basic_Auth 产生另一个意外行为。

所以目前我有点不知道如何解决这个问题。

【问题讨论】:

    标签: nginx reverse-proxy nginx-location


    【解决方案1】:

    请从您的位置指令中删除尾随的/,或在访问它们时提供/

    Nginx 寻找最长的前缀匹配位置。当你访问http://localhost:8080/apex时,它被路由到/,因为/apex/不是/apex的前缀

    location 的文档是 here

    【讨论】:

    • 这对我来说听起来很有效。你有什么想法,为什么 nginx 要求我输入顶点端点的用户名和密码?这仅在我使用静态网站打开 URL 后发生。这可能与我的第一个问题有关吗?
    • 我认为这是同一个问题。如果您仍有问题,请提供更多详细信息。谢谢。
    • 让我测试一些东西。我有一种感觉,也许我正在使用的服务人员会导致一些问题。如果我输入localhost:8080/apex,我仍然可以访问静态网站。
    【解决方案2】:

    我现在尝试了几件事,但都没有真正奏效。所以我决定为我当前设置有问题的所有位置指令创建第二个服务器块。

    这可能不是最好的解决方案,因为我仍然不知道为什么会遇到这些问题。但它现在有效,这对我来说很重要。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-06-09
      • 2012-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-15
      • 1970-01-01
      相关资源
      最近更新 更多