Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
242 views
in Technique[技术] by (71.8m points)

how to set up basic authentication for node.js app using nginx?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...