我已经设置了一个测试 Virtualbox/Debian Wheezy7.1 机器,带有一个裸网安装机器 + nginx + php-fpm
我有 SSL、php、basic_auth 和允许/拒绝在服务器级别上工作。
但是,如果我希望 auth 内容仅用于一个路径,则 auth 可以工作,但 PHP 内容不能(index.php 在 Web 浏览器中下载)
我知道这与 nginx 如何匹配位置指令有关,但我不确定它是什么......
这是我的配置文件:
server {
listen 80;
server_name www.test.com;
rewrite ^ https://$server_name$request_uri? permanent;
}
# HTTPS server
server
{
listen 443;
server_name www.test.com;
root /srv/vhosts/www.test.com/html;
index index.php ;
ssl on;
ssl_certificate /etc/nginx/certs/STAR.test.com.crt;
ssl_certificate_key /etc/nginx/certs/STAR.test.com.key;
ssl_session_timeout 5m;
ssl_protocols SSLv3 TLSv1;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;
ssl_prefer_server_ciphers on;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
location ^~ /testdir/ {
auth_basic "gib login";
auth_basic_user_file /etc/nginx/htpasswd/www.test.com.htpasswd;
allow 192.168.1.3; # my workstation ip
deny all;
}
}
编辑:看第一条评论,谢谢!