Nginx и .htpasswd
kosgtx
nginx-forum at nginx.us
Wed Feb 6 16:52:55 UTC 2013
Вечер бодрый!
Столкнулся с неприятностью, в виде невозможности установить корректно
работающую аутентификацию на аудиторию.
У меня сервер CentOS + ISPConfig + Nginx, стоит скрипт интернет-магазина
Simpla с конфигом следующего вида:
server {
listen *:80;
server_name somedomain.com.ua www.somedomain.com.ua;
root /var/www/somedomain.com.ua/web;
index index.html index.htm index.php index.cgi index.pl
index.xhtml;
error_page 400 /error/400.html;
error_page 401 /error/401.html;
error_page 403 /error/403.html;
error_page 404 /error/404.html;
error_page 405 /error/405.html;
error_page 500 /error/500.html;
error_page 502 /error/502.html;
error_page 503 /error/503.html;
recursive_error_pages on;
location = /error/400.html {
internal;
}
location = /error/401.html {
internal;
}
location = /error/403.html {
internal;
}
location = /error/404.html {
internal;
}
location = /error/405.html {
internal;
}
location = /error/500.html {
internal;
}
location = /error/502.html {
internal;
}
location = /error/503.html {
internal;
}
error_log /var/log/ispconfig/httpd/somedomain.com.ua/error.log;
access_log /var/log/ispconfig/httpd/somedomain.com.ua/access.log
combined;
## Disable .htaccess and other hidden files
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location /stats {
index index.html index.php;
auth_basic "Members Only";
auth_basic_user_file
/var/www/clients/client1/web11/.htpasswd_stats;
}
location ^~ /awstats-icon {
alias /usr/share/awstats/icon;
}
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/lib/php5-fpm/web11.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_intercept_errors on;
}
location /cgi-bin/ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
root /var/www/clients/client1/web11;
gzip off;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
fastcgi_index index.cgi;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
}
location ^~ /simpla/ {
auth_basic "Administrator Login";
auth_basic_user_file $document_root/simpla/.htpasswd;
try_files $uri $uri/ /index.php;
index index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include /etc/nginx/fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_pass unix:/var/lib/php5-fpm/web11.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME
$document_root/$fastcgi_script_name;
}
}
location ~ /\. { deny all; }
location ~*
^/(api|cache|compiled|config|design/(.*)/html|payment|Smarty|view)/(.*) {
deny all; }
location / {
try_files $uri @rewrite;
}
location @rewrite {
rewrite ^/catalog/([^/]+)/?$
index.php?module=ProductsView&category=$1;
rewrite ^/catalog/([^/]+)/([^/]+)/?$
index.php?module=ProductsView&category=$1&brand=$2;
rewrite ^/products/([^/]+)/?$
index.php?module=ProductView&product_url=$1;
rewrite ^/products/?$ index.php?module=ProductsView;
rewrite ^/brands/([^/]+)/?$
index.php?module=ProductsView&brand=$1;
rewrite ^/brands/([^/]+)/page_([^/]+)/?$
index.php?module=ProductsView&brand=$1&page=$2;
rewrite ^/search/([^/]+)/?$
index.php?module=ProductsView&keyword=$1;
rewrite ^/search/?$ index.php?module=ProductsView;
rewrite ^/blog/([^/]+)/?$
index.php?module=BlogView&url=$1;
rewrite ^/blog/?$ index.php?module=BlogView;
rewrite ^/cart/?$ index.php?module=CartView;
rewrite ^/cart/([^/]+)/?$
index.php?module=CartView&add_variant=$1;
rewrite ^/cart/remove/([^/]+)/?$
index.php?module=CartView&delete_variant=$1;
rewrite ^/order/([^/]+)/?$
index.php?module=OrderView&url=$1;
rewrite ^/order/?$ index.php?module=OrderView;
rewrite ^/user/login/?$ index.php?module=LoginView;
rewrite ^/user/register/?$
index.php?module=RegisterView;
rewrite ^/user/logout/?$
index.php?module=LoginView&action=logout;
rewrite ^/user/password_remind/?$
index.php?module=LoginView&action=password_remind;
rewrite ^/user/password_remind/([0-9a-z]+)/?$
index.php?module=LoginView&action=password_remind&code=$1;
rewrite ^/user/?$ index.php?module=UserView;
rewrite ^/sitemap.xml?$ sitemap.php last;
rewrite ^/yandex.xml?$ yandex.php last;
rewrite ^/contact/?$ index.php?module=FeedbackView;
rewrite ^/order/([^/]+)/([^/]+)/?$
index.php?module=OrderView&url=$1&file=$2;
if (!-f $request_filename){
set $rule_26 1$rule_26;
}
if (!-d $request_filename){
set $rule_26 2$rule_26;
}
if ($rule_26 = "21"){
rewrite ^/([^/]*)/?$
index.php?module=PageView&page_url=$1;
}
rewrite ^/?$ index.php?module=MainView&page_url=;
rewrite ^ /index.php;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include /etc/nginx/fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_pass unix:/var/lib/php5-fpm/web11.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME
$document_root/$fastcgi_script_name;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
if (!-d $request_filename){
set $rule_28 1$rule_28;
}
if (!-f $request_filename){
set $rule_28 2$rule_28;
}
if ($rule_28 = "21"){
rewrite ^/files/products/(.+)
resize/resize.php?file=$1&token=$args;
}
expires max;
log_not_found off;
}
}
Когда ввожу с адресную строку somedomain.com.ua/simpla/index.php просит
логин и пароль, ввожу и данные принимает, но вместо открытия админки,
скачивает файл index.php, если уберу необходимость аутентификации, войти
могу без проблем и все работает.
Кто что подскажет?
Posted at Nginx Forum: http://forum.nginx.org/read.php?21,235962,235962#msg-235962
Подробная информация о списке рассылки nginx-ru