Answer the question
In order to leave comments, you need to log in
How to attach simple authorization to the site (nginx rewrite + htpasswd)?
Good afternoon!
It is not possible to fasten simple authorization to the site in any way.
What we have: nginx + php + fpm and a simple site in php.
Host config:
server {
listen 80;
server_name test.site.ru;
root /var/www/test.site.ru/web;
error_log /var/log/ispconfig/httpd/test.site.ru/error.log;
access_log /var/log/ispconfig/httpd/test.site.ru/access.log combined;
location / {
index index.php;
auth_basic "Members Only";
auth_basic_user_file /etc/nginx/htpasswd;
#правила перенес из htaccess
rewrite ^/image /image.php last;
rewrite ^/web/(.*) /web/$1 last;
rewrite ^/receiver.html /receiver.html last;
rewrite ^/ /index.php last;
}
Images and static content is treated different
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
access_log off;
expires 360d;
}
location ~ /\.ht {
deny all;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
rewrite ^/ /index.php last;
Authorization works
without the directive , but further on all links 404 error. Authorization does not work with the rule. Answer the question
In order to leave comments, you need to log in
I tried it, it worked. Thank you :)
If it's not difficult, in a nutshell, why didn't it work before? You can link to the documentation.
enter in server
error_page 555 = @pass;
location @pass {
auth_basic "Unauthorized";
auth_basic_user_file /var/www/dev_htpasswd;
proxy_pass http://127.0.0.1:82;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
if ($http_host ~* "^(dev|old|www.old|www.dev)\..*\..{2,8}$"){
return 555;
}
if ($http_host ~* "^.*\.ks03\.ru$"){
return 555;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question