我是nginx的新手,我想把我的网站从Apache迁移到nginx。我的网站的URL如下:
Www.mywebsite.com/类别/产品/气球
Www.mywebsite.com/类别/产品/鞋
www.mywebsite.com/information/help
等。
由于我使用的是PHP,所以我需要将所有的URL重写为index.php,除非它是一个图像或者是一个“伪请求”。到目前为止我的nginx.config:
#block fake requests
location ~* \.(aspx|jsp|cgi)$ {
return 410;
}
#rewrite all requests if it's not a image
location / {
root html;
index index.php 500.html;
if (!-f $request_filename) {
rewrite ^(.*)$ /index.php?q=$1 last;
break;
}
}
error_page 404 /index.php;
# serve static files directly
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico)$ {
access_log off;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME E:/test2/html/$fastcgi_script_name;
include fastcgi_params;
}此配置不起作用,原因是:
它不会阻止对.php文件的虚假请求,我也不能向添加
如果它是已定义的文件类型in(jpg|jpeg|gif|css|png|js|ico)$,则不能确定
我该如何解决这些问题呢?我真的很感谢你能给我的每一个回答,澄清或反馈。
谢谢,迈克
发布于 2012-03-03 05:45:18
您需要配置HttpRewriteModule。此模块允许使用正则表达式(PCRE)更改URI,并根据变量重定向和选择配置。
如果此模块的指令是在服务器级别给出的,则在确定请求的位置之前执行这些指令。如果在所选位置中有更多重写指令,则也执行它们。如果URI由于在location内执行指令而发生更改,则会再次为新URI确定位置。
https://stackoverflow.com/questions/7390694
复制相似问题