Answer the question
In order to leave comments, you need to log in
All server authorization using the auth_basic directive, except for one ip?
Hello everyone I
just recently started learning Nginx
Tell me how to make everyone require prior authorization using the auth_basic directive,
except for clients with a specific ip (for example 11.22.33.44)
This is how I wanted to do it,
I will store logins and passwords in /etc/nginx/passwrds;
if ($remote_addr != 11.22.33.44) {
auth_basic "Oops(";
auth_basic_user_file /etc/nginx/passwrds;
}
server {
listen 80;
server_name _;
server_tokens off;
proxy_set_header X-Forwarded-For $remote_addr;
location / {
allow 11.22.33.44;
deny all;
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_read_timeout 1200s;
# used for view/edit office file via Office Online Server
client_max_body_size 0;
access_log /var/log/nginx/ access.log;
error_log /var/log/nginx/ error.log;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question