使用Nginx在flask应用程序中保护一条路由的密码

使用Nginx在flask应用程序中保护一条路由的密码,nginx,flask,Nginx,Flask,我有一个restful服务,我想使用nginx用用户名/密码保护一个特定的路由。当用户输入url时,他会得到一个excel文件(报告)。 我按照教程创建了简单的身份验证。我添加了这里提到的参数,但没有效果。这是我的配置文件: server { listen 80; real_ip_header X-Forwarded-For; set_real_ip_from 127.0.0.1; server_name localhost; root /var/www/html/psycho-test-re

我有一个restful服务,我想使用nginx用用户名/密码保护一个特定的路由。当用户输入url时,他会得到一个excel文件(报告)。 我按照教程创建了简单的身份验证。我添加了这里提到的参数,但没有效果。这是我的配置文件:

server {
listen 80;
real_ip_header X-Forwarded-For;
set_real_ip_from 127.0.0.1;
server_name localhost;

root /var/www/html/psycho-test-rest/psycho_front/dist;

location /tests/get_all_users {
include uwsgi_params;
uwsgi_pass unix:/var/www/html/psycho-test-rest/socket.sock;
uwsgi_modifier1 30;
auth_basic "Restricted Content";
auth_basic_user_file /etc/nginx/.htpasswd;
}

location ~ ^/(tests|CRUD)/ {
include uwsgi_params;
uwsgi_pass unix:/var/www/html/psycho-test-rest/socket.sock;
uwsgi_modifier1 30;
}

error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
/测试/获取所有用户是我要保护的位置。当我在浏览器中输入url时,我会得到文件,但nginx不会要求输入密码。配置文件有问题吗?我不确定这是否重要,但https尚未启用。在我为这条路线设置了密码之后,我正在考虑设置它

我正在ubuntu 16.04上部署。

在一条路径上使用类似“
login\u required
”的装饰程序:

def loginRequired():
    if not session.get('logged_in'):
        if not request.endpoint == 'dashboard_route.loginPage':
            return redirect(url_for('dashboard_route.loginPage'))

@loginRequired
@mod.route("/")
def dashHome():
    return render_template('index.html')