![Nginx 重定向规则到子目录](https://linux22.com/image/768569/Nginx%20%E9%87%8D%E5%AE%9A%E5%90%91%E8%A7%84%E5%88%99%E5%88%B0%E5%AD%90%E7%9B%AE%E5%BD%95.png)
我有一个旧的 PHP 应用程序在 Apache 上运行,现在我需要切换到使用 Nginx
htaccess 重定向规则
php_value upload_max_filesize "5M"
AddType text/x-component .htc
RewriteEngine On
RewriteBase /brand/kit/summer-icecream/lacne
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(/admin/)
RewriteCond %{REQUEST_URI} !(/setup/)
RewriteCond %{REQUEST_URI} !(/support/)
RewriteCond %{REQUEST_URI} !(/share/)
RewriteCond %{REQUEST_URI} !(/rss/)
RewriteCond %{REQUEST_URI} !(/output/)
RewriteCond %{REQUEST_URI} !(/upload/)
RewriteCond %{REQUEST_URI} !(/app_api/)
RewriteRule ^(.+)\.php$ share/admin/$1.php [L]
RewriteRule app_api/(.+)\.php$ share/app_api/$1.php [L]
我尝试了几种重定向方法,例如下面这些,但似乎根本不起作用,它没有将 PHP 文件传递给 PHP-FPM
location ~ brand/kit/summer-icecream/lacne/(.+)\.php$ {
if (!-e $request_filename){
rewrite ^/brand/kit/summer-icecream/lacne/(.+)\.php$ /brand/kit/summer-icecream/lacne/share/admin/$1.php redirect;
}
}
location ~ (.+)\.php$ {
try_files $uri =404;
fastcgi_pass fastcgi_backend;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_read_timeout 600s;
fastcgi_connect_timeout 600s;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param HTTP_HOST $host;
include /etc/nginx/fastcgi_config;
}
为了测试,请求 URI 为: http://127.0.0.1:8989/brand/kit/summer-icecream/lacne/login.php