求Nginx下CI的urlrewrite规则
http://localhost/account/auth在apache下可以的,但在nginx里就行不能了,显示404,
以下是nginx的配置节:
server {
listen 8000;
server_nameuc.xxx.com;
location / {
root /u/game/html/UCenter;
indexindex.php index.html index.html;
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
}
}
location ~ \.php$ {
root /u/game/html/UCenter;
fastcgi_pass 127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME/u/game/html/UCenter$fastcgi_script_name;
include fastcgi_params;
}
}
只能通过http://localhost/index.php?c=account&m=auth来访问。
怎么改一下?
location / {
index index.php;
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}
这个是从typecho的nginx的rewrite rule改的,我自己测试可以用。
或者,刚才还看到这个apache到nginx规则转换的网站,你可以试试,我自己没试过。
http://www.anilcetin.com/convert-apache-htaccess-to-nginx/ huboo82 发表于 2012-2-7 15:22 static/image/common/back.gif
这个是从typecho的nginx的rewrite rule改的,我自己测试可以用。
或者,刚才还看到这个apache到nginx规则 ...
按照你的修改之后,直接500错误了。。。
http://localhost/account/get
而这样却是可以访问的:
http://localhost/index.php?c=account&m=get
改了nginx的配置需要重载生效 huboo82 发表于 2012-2-7 17:37 static/image/common/back.gif
改了nginx的配置需要重载生效
谢谢,重启了nginx,但还是500错,打开调试信息,发现rewrite后,一直无限重定向,才造成500错,以下是日志:
2012/02/07 18:23:51 23398#0: *2025 rewrite or internal redirection cycle while processing "/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/account/get", client: 172.17.170.28, server: localhost, request: "GET /account/get HTTP/1.1", host: "localhost:80"
怎么会这样呢?rewrite有错么? 这是我正在用的,虚拟机,lnmp
server
{
listen 80;
server_name www.test.com;
index index.php index.html index.htm;
root/home/wwwroot;
location ~ .*\.(php|php5)?$
{
fastcgi_passunix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
}
location / {
index index.php;
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}
}
huboo82 发表于 2012-2-7 19:09 static/image/common/back.gif
这是我正在用的,虚拟机,lnmp
server {
listen 80;
server_namelocalhost;
location / {
root /u/game/html/www;
indexindex.php index.html index.htm;
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}
访问
http://localhost/account/get
还是出错:
2012/02/08 08:49:29 23398#0: *2061 rewrite or internal redirection cycle while processing "/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/account/get", client: 127.0.0.1, server: localhost, request: "GET /account/get HTTP/1.1", host: "127.0.0.1:80"
唉~~~
location ~ .*\.(php|php5)?$
{
fastcgi_pass127.0.0.1:8888;
fastcgi_index index.php;
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
include fastcgi.conf;
}
} 你试试装个 typecho 看看,这个也是单入口文件的,如果这个没问题,你就要查查你程序上的问题了。 huboo82 发表于 2012-2-8 09:54 static/image/common/back.gif
你试试装个 typecho 看看,这个也是单入口文件的,如果这个没问题,你就要查查你程序上的问题了。 ...
根目录下的index.php入口文件我,我只有
print_r($_GET);
exit;
为了调试,文件里只有这些内容。
我找个享悉配置的人看看吧。。 终于找到一个可用的:
server {
listen 8020;
root /u/game/html/BCenter/;
index index.php index.html index.htm;
location / {
if (-f $request_filename) {
expires max;
break;
}
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
}
}
location = /50x.html {
root /var/www/nginx-default;
}
location /index.php {
fastcgi_pass 127.0.0.1:8888;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /u/game/html/BCenter/index.php;
include fastcgi_params;
}
}
这个已经可用了。
页:
[1]
2