【问题标题】:nginx location directive : authentication happening in wrong location block?nginx 位置指令:身份验证发生在错误的位置块中?
【发布时间】:2011-12-23 07:21:50
【问题描述】:

我很困惑。

我有一个服务器,它主要通过 ssl 运行 couchdb(使用 nginx 代理 ssl 连接),但还必须提供一些 apache 的东西。

基本上,我希望将不启动 /www 的所有内容发送到 couchdb 后端。如果一个 url 以 /www 开头,那么它应该映射到本地 apache 服务器的 8080 端口。

我的下面的配置可以正常工作,但也会提示我在 /www 路径上进行身份验证。我比 nginx 更习惯于配置 Apache,所以我怀疑我误解了一些东西,但如果有人能从我的配置中看出什么问题(如下),我将不胜感激。

澄清我的使用场景;

  1. https://my-domain.com/www/script.cgi 应该被代理到 http://localhost:8080/script.cgi
  2. https://my-domain.com/anythingelse 应该被代理到 http://localhost:5984/anythingelse

只有第二个需要身份验证。导致问题的是身份验证问题 - 正如我所提到的,我也在 https://my-domain.com/www/anything 上受到挑战:-(

这是配置,感谢您的任何见解。

server {
        listen   443;
        ssl on;

        # Any url starting /www needs to be mapped to the root
        # of the back end application server on 8080

        location ^~ /www/ {
        proxy_pass http://localhost:8080/;
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        }

        # Everything else has to be sent to the couchdb server running on
        # port 5984 and for security, this is protected with auth_basic
        # authentication.

        location / {

        auth_basic "Restricted";
        auth_basic_user_file /path-to-passwords;

        proxy_pass http://localhost:5984;
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Ssl on;

        }
    }

【问题讨论】:

    标签: authentication configuration proxy nginx location


    【解决方案1】:

    Maxim 通过提到访问网站图标的浏览器会触发此行为并且配置在其他方面是正确的,帮助我回答了这个问题。

    【讨论】:

      猜你喜欢
      • 2018-03-07
      • 2021-08-21
      • 1970-01-01
      • 1970-01-01
      • 2020-06-02
      • 2012-11-09
      • 1970-01-01
      • 2014-04-05
      • 1970-01-01
      相关资源
      最近更新 更多