Nginx Rewrite失败,请教一下怎么改?
我基于PHP开发了一个短网址程序,之前放在Apace服务器上面,运行很正常,但是转到Nginx服务器上面之后,我自己写了新的Rewrite规则,但是URL重写老是失败。在Chrome下面会下载PHP源码文件,在IE下会直接输出PHP源码。我想把类似'oooo. com/r.php?id=xxx'的网址转换成'oooo. com/xxx'形式。我的短网址程序的Nginx配置文件内容如下:
server {
listen 80;
server_name oooo.com www.oooo.com;
access_log off;
index index.html index.htm index.jsp index.php;
include none.conf;
root /home/wwwroot/oooo.com;
#rewrite_log on;
#error_log logs/oooo-error.log notice;
location / {
#index index.html index.htm index.php;
rewrite ^/([a-zA-Z0-9_-]+)$ /r.php?id=$1 break;
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}
#error_page 404 /404.html;
if ( $query_string ~* ".*[\;'\<\>].*" ){
return 404;
}
location ~ .*\.(wma|wmv|asf|mp3|mmf|zip|rar|jpg|gif|png|swf|flv)$ {
valid_referers none blocked *.oooo.com oooo.com www.oooo.com;
if ($invalid_referer) {
#rewrite ^/ http://www.linuxeye.com/403.html;
return 403;
}
}
location ~ .*\.(php|php5)?$ {
#fastcgi_pass remote_php_ip:9000;
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
expires 30d;
}
location ~ .*\.(js|css)?$ {
expires 7d;
}
}
我自己觉得应该是没有问题的,但事实一次次打击我。不知道是不是MIME的问题,烦请高手告诉我,怎么改,又该改哪里?
帕金森太一
9 years, 8 months ago