2015年10月06日 | 3934
最近将代码从apache 环境 下移植到 nginx 下面,居然报了404错误。通过查询得知,是由于 nginx
重写不支持apache的.htaccess所致。
说明一点nginx 不支持PATH_INFO 自己找解决方法
在 nginx 的配置文件nginx.conf中添加如下代码即可:
location / { if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=$1 last; break; } }
如,我的配置文件添加如下代码之后的代码:
server { listen 80; server_name test.nginx.com; index index.html index.htm index.php; root /data0/htdocs/wwwroot/www; #limit_conn crawler 20; location / { if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=$1 last; break; } } location ~ .*\.(php|php5)?$ { #fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fcgi.conf; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 1h; } }
Apache下
.htaccess
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]