代码之家  ›  专栏  ›  技术社区  ›  Alan Omar

如何从Nginx上的基本身份验证中排除路由?

  •  0
  • Alan Omar  · 技术社区  · 7 年前

    我有nginx服务器,它后面运行着一个Django应用程序,服务器通过基本的身份验证得到保护。我想从身份验证中排除一些端点,例如:

    /api/v1/testpoint/?search=48

    我试过了 this 但我得到404。

    0 回复  |  直到 7 年前
        1
  •  0
  •   Alan Omar    7 年前

    在我的例子中,我在我的 mysite :

    location /api/v1/testpoint/ {
        auth_basic off;
    }
    

    /api/v1/testpoint/

    404 错误,因为当请求到达时 /api/v1/testpoint/?search=48 Nginx试图提供相对于其默认公共web根目录的请求。

    nginx通过运行在端口9090上的uWsgi服务器与django应用程序通信。

    所以我修改了上面的块:

    location /api/v1/testpoint/ {
        auth_basic  off;
        uwsgi_pass  127.0.0.1:9090;
        include  uwsgi_params;
    }
    

    这就解决了问题。