Welcome! Log In Create A New Profile

Advanced

Re: limit_except - require trusted ip AND auth vs. ip OR auth

Patrick
June 18, 2019 11:04PM
On 2019-06-18 16:41, Matthias Müller wrote:
> 1) Permit POST, PUT if the request matches a trusted IP address OR
> Basic auth credentials (either-or)

Something like this will work:

map $remote_addr $is_admin {
1.2.3.4 1;
default 0;
}

map $is_admin$request_method $admin_required {
"GET" 0;
"HEAD" 0;
"OPTIONS" 0;
"~1.*" 0;
default 1;
}

server {
listen 80;
server_name localhost;
access_log /var/log/nginx/access.log combined;

location @loc_A {
root /srv/www;
try_files $uri =404;
}

location @loc_A_auth {
auth_basic 'Restricted';
auth_basic_user_file /etc/nginx/htpasswd;
try_files /NO-SUCH-FILE @loc_A;
}

location /a {
recursive_error_pages on;
error_page 598 = @loc_A;
error_page 599 = @loc_A_auth;
if ( $admin_required ) {
return 599;
}

return 598;
}
}

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

limit_except - require trusted ip AND auth vs. ip OR auth

Matthias Müller June 18, 2019 10:42AM

Re: limit_except - require trusted ip AND auth vs. ip OR auth

Patrick June 18, 2019 11:04PM

Re: limit_except - require trusted ip AND auth vs. ip OR auth

Patrick June 18, 2019 11:14PM

Re: limit_except - require trusted ip AND auth vs. ip OR auth

Maxim Dounin June 19, 2019 08:34AM

Re: limit_except - require trusted ip AND auth vs. ip OR auth

Matthias Müller June 21, 2019 03:30AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 138
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready