【发布时间】:2016-11-03 15:29:25
【问题描述】:
我在树莓派上安装了 nginx。在/etc/nginx/sites-available/default 中,我将server{} 替换为以下内容,我可以使用http://192.168.1.210/ 访问/var/www/html/index.php。
server {
listen 80;
server_name $domain_name;
root /var/www/html/;
index index.html index.htm;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location ~\.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
try_files $uri =404;
include fastcgi_params;
# if (!-e $request_filename){ rewrite ^(.*)$ /index.php break; }
}
}
我现在希望添加一些类似于 Apache 的简单重定向
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
我在最后添加了if (!-e $request_filename){ rewrite ^(.*)$ /index.php break;(参见上面注释掉的行)并将http://192.168.1.210/page2放在浏览器中,但是脚本仍然没有重定向到/var/www/html/index.php
如何将任何不存在的请求重定向到 index.php?
【问题讨论】: