nginx不能支持.htaccess的rewrite规则,所以使用nginx作web服务器,配置wordpress固定链接会比较麻烦一点,要自己写规则到nginx配置文件里。网上也看到一些配置规则,不过觉得怪怪的。
发现nginx官方网站上有个页面,关于wordpress重写规则的,http://wiki.nginx.org/WordPress里面有“cool”的规则,本站的nginx配置如下,其中一行 try_files $uri $uri/ /index.php; 就是这行,应该比网上有些文章里的规则更cool。
server {
server_name blog.path8.net;
root /var/www/vhost/blog;
access_log logs/vhost-blog.path8.net.log main;
location /favicon.ico {
log_not_found off;
access_log off;
}
location /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location / {
index index.html index.htm index.php;
# from nginx.org rewrite rule
# This is cool because no php is touched for static
try_files $uri $uri/ /index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/vhost/blog$fastcgi_script_name;
include fastcgi_params;
}
}
评论关闭。