我有像 Ucp.php Somesite.php 这样的文件,我想为 nginx 创建一个重写规则。这没有问题。
但我也想阻止对那些 php 文件的直接访问,这样 enetring http://mysite.com/Ucp.php将返回 404 Not Found。
apache 有一个解决方案(使用 THE_REQUEST),但我如何在 nginx 上执行此操作?
server
{
listen 80;
server_name site.com;
root /home/site/public_html;
index Main.php;
rewrite ^/SomeAddr/$ /SomeAddr.php last;
rewrite ^/SomeOtherAddr/$ /SomeOtherAddr.php last;
location ~ \.php$
{
fastcgi_pass unix:/var/run/php-fpm/site_com.sock;
include fastcgi.conf;
}
include security.conf;
}
最佳答案
您可以使用 internal
directive为此目的。
location ~ \.php$
{
internal;
fastcgi_pass unix:/var/run/php-fpm/site_com.sock;
include fastcgi.conf;
}
关于url-rewriting - 使用 nginx 阻止直接访问 php 文件(仅重写),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16541090/