0

I'm trying to add basic authentication to a nginx reverse proxy which is in front of a nuxtjs app.

I've configured nginx as so

    server {

    server_name <url>;

    auth_basic "Restricted Content";
    auth_basic_user_file /etc/nginx/.htpasswd;


gzip            on;
gzip_types      text/plain application/xml text/css application/javascript;
gzip_min_length 1000;

location / {


    proxy_pass http://127.0.0.1:3222;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
}

listen 443 ssl; # managed by Certbot

But if hangs. I've also tried it in the location section, but this hangs too, what am I missing?

The .htpasswd file exists with the correct details in.

Have also tried changing

upstream backend {
server backend1.example.com       weight=5;
server backend2.example.com:8080;
server unix:/tmp/backend3;

server backup1.example.com:8080   backup;
server backup2.example.com:8080   backup;
}

server {
location / {
    proxy_pass http://backend;
}
}

to something similar to this, but still no luck

EDIT: I have gone through various posts and have adjusted a number of the nginx proxy_pass timeout settings, although I have had no successes.

upstream backend {
server 127.0.0.1:3222;
keepalive 7000;
}

and

    auth_basic "Restricted Content";
    auth_basic_user_file conf.d/.htpasswd;


    proxy_pass http://backend;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
    proxy_read_timeout 7200s;
    proxy_connect_timeout 75s;
    proxy_buffer_size 8k;
    proxy_set_header  Authorization $http_authorization;
    proxy_pass_header Authorization;

}

The only error I can see is in my pm2 logs

ERROR Request failed with status code 401

at createError (node_modules/axios/lib/core/createError.js:16:15)
at settle (node_modules/axios/lib/core/settle.js:17:12)
at IncomingMessage.handleStreamEnd (node_modules/axios/lib/adapters/http.js:269:11)
at IncomingMessage.emit (events.js:327:22)
at endReadableNT (_stream_readable.js:1220:12)
|   at processTicksAndRejections (internal/process/task_queues.js:84:21)

Thanks to all that have helped so far.

user2099762
  • 173
  • 2
  • 12
  • Are there any hints that you might find in /var/log/nginx/*? How was the htpasswd file generated? – Aaron T Jul 20 '22 at 10:25
  • Generted using sudo htpasswd /etc/nginx/.htpasswd another_user nginx logs are empty – user2099762 Jul 20 '22 at 10:27
  • apart from 2022/07/20 11:16:33 [error] 21224#21224: *1977925 upstream timed out (110: Connection timed out) while reading response header from upstream, client: , server: request: "GET / HTTP/2.0", upstream: "http://127.0.0.1:3222/", host: – user2099762 Jul 20 '22 at 10:29
  • This answer from here might help you, you can include a higher proxy time out setting by `proxy_read_timeout 3600;` at whichever part you're facing the timeout. Answer picked from https://stackoverflow.com/questions/18740635/nginx-upstream-timed-out-110-connection-timed-out-while-reading-response-hea. – Aaron T Jul 21 '22 at 01:59

0 Answers0