我已经设置了一个测试的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;
}
}
编辑:看第一条评论,谢谢!
根据nginx文档,位置指令的顺序很重要。
为了确定哪个位置指令与特定查询匹配,首先检查文字字符串。文字字符串匹配查询的开头部分-将使用最具体的匹配项。然后,以配置文件中定义的顺序检查正则表达式。第一个与查询匹配的正则表达式将停止搜索。如果找不到正则表达式匹配项,则使用文字字符串搜索的结果。
尝试组织位置指令,以便首先保护目录,然后是PHP,然后是try__files
指令。我对系统进行了快速测试,并按照以下顺序构造了位置块:允许testdir
对其进行保护并index.php
仍然可以执行。
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;
}
location ~ \.php$ {
}
location ~ / {
try_files $uri $uri/ 404;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句