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.