如何解决如何使用 nginx 为 node.js 应用程序设置基本身份验证?
我必须使用 node.js app
为 nginx
设置基本身份验证。
- node.js 在 8080 上运行
- nginx 运行在 80 端口
我是新手,我在 nginx.conf
中尝试过这种配置。找不到我在 nginx.conf
文件中所做的解决方案更改。 test-demo 是我用于服务器配置的负载平衡器名称。
# nginx.conf
upstream test-demo{
# Nodejs App upstream
server 127.0.0.1:8080;
keepalive 64;
}
server {
listen 80;
listen [::]:80;
server_name www.example.com;
root /usr/share/nginx/html;
auth_basic "Administrator Login";
auth_basic_user_file /etc/nginx/.htpasswd;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
#Proxy_pass configuration
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Keep-Alive";
proxy_max_temp_file_size 0;
proxy_pass http://test-demo;
proxy_redirect off;
proxy_read_timeout 240s;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。