I have to set up basic authentication for node.js app
using nginx
.
- node.js is running on 8080
- nginx is running on port 80
I'm new to this & I tried with this configuration in nginx.conf
. can't find the solution changes which i have made in nginx.conf
file. test-demo is load-balancer name which i'm using for server configuration.
# 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;
}
}
question from:
https://stackoverflow.com/questions/65843565/how-to-set-up-basic-authentication-for-node-js-app-using-nginx 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…