问题
我试图拒绝访问我的web根目录中的两个文件,update.php,install.php,并要求对apc.php(也是webroot)进行身份validation。
我想我已经成功地拒绝访问,但打开文件下载而不是运行。
例如,inputIPADDRESS / apc.php的authentication后,下载到我的电脑而不是打开。 同样的事情发生的update.php。
如果我删除引用这三个文件的块,它会成功,但当然,他们不被阻止。 我怎样才能解决这个问题?
至今
(我已经重新安排把相关的块带到最上面。)
我认为问题是这样的:
我唯一能find的位置匹配是^〜,所有其他的都被忽略(为什么?),expression式^〜匹配后停止search,所以我认为它从来没有findPHP块。 所以它下载而不是运行。
我试图添加phpconfiguration给块:
location ^~ /update.php { allow 127.0.0.1; deny all; fastcgi_param SCRIPT_FILENAME /srv/www/mysite/public$fastcgi_script_name; fastcgi_pass 127.0.0.1:9000; include /etc/nginx/fastcgi_params; }
但这只是使页面变成空白。
服务器configuration
server { listen 8080; server_name website website.com; access_log /srv/www/website/logs/access.log; error_log /srv/www/website/logs/error.log; root /srv/www/website/public; location / { index index.php index.html index.htm; error_page 404 = @drupal; } ##deny access to update and install for everyone except the server location ^~ /update.php { allow 127.0.0.1; deny all; } location ^~ /install.php { allow 127.0.0.1; deny all; } ##authentication required to access apc.php location ^~ /apc.php { auth_basic "Restricted access"; #realm auth_basic_user_file /srv/www/website/public/.htpasswd-users; } ##drupal rewrite rules location @drupal { rewrite ^(.*)$ /index.php?q=$1 last; } ##secure private file directory location ~* /privatefiles { internal; } ##Add headers to advagg location ~* files/advagg_(?:css|js)/ { access_log off; expires max; add_header ETag ""; add_header Cache-Control "max-age=290304000, no-transform, public"; add_header Last-Modified "Wed, 20 Jan 1988 04:20:42 GMT"; try_files $uri @drupal; } ## Replicate the Apache <FilesMatch> directive of Drupal standard ## .htaccess. Disable access to any code files. Return a 404 to curtail ## information disclosure. Hide also the text files. location ~* ^(?:.+\.(?:htaccess|make|txt|log|engine|inc|info|install|module|profile|po|sh|.*sql|theme|tpl(?:\.php)?|xtmpl)|code-style\.pl|/Entries.*|/Repository|/Root|/Tag|/Template)$ { return 404; } location ~ \..*/.*\.php$ { return 403; } ##rules for running php location ~ \.php$ { try_files $uri =404; include /etc/nginx/fastcgi_params; if ($uri !~ "^/default/files/") { fastcgi_pass 127.0.0.1:9000; } fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /srv/www/website/public$fastcgi_script_name; } }
可能是这个expression
location ^~ /...
是错的? 不应该读取:
location ~ ^/...
?
为什么你需要在这里正则expression?
location /install.php
应该可以。