Answer the question
In order to leave comments, you need to log in
nginx frontend rewrite. Why ERR_TOO_MANY_REDIRECTS?
Hello!
The point is the following. Nginx acts as a frontend. Task: redirect some clients by IP addresses not from the list to a separate page. The config seems to be set up, but the browser does not open the page and writes an error - ERR_TOO_MANY_REDIRECTS.
Tell me, please, how to fix it?
nginx config:
server {
listen 80;
server_name domainname.ru;
server_name www.domainname.ru;
if ($remote_addr != *.*.*.*) {
rewrite ^ http://domainname.ru/temp.html;
}
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
proxy_buffers 16 64k;
proxy_buffer_size 128k;
location / {
proxy_pass http://172.17.22.1;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_redirect off;
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-Proto https;
}
}
~
Answer the question
In order to leave comments, you need to log in
To deny access via IP, there is an access module and allow / deny directives .
server {
listen 80;
server_name domainname.ru;
server_name www.domainname.ru;
# прочие настройки
location / {
# разрешаем доступ с определённых IP и подсетей
allow 192.168.1.0/24; # подсеть 192.168.1.0–192.168.1.255
allow 2.2.3.3; # конкретный IP адрес
deny all; # всем остальным запретить
# всем кому запретили покажем страницу /temp.html
error_page 403 /temp.html;
proxy_pass http://172.17.22.1;
# ... прочие proxy_...
}
location /temp.html {
# тут в общем-то ничего не нужно
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question