从 apache 到 nginx:wordpress 重写规则

Posted

技术标签:

【中文标题】从 apache 到 nginx:wordpress 重写规则【英文标题】:From apache to nginx: wordpress rewrite rule 【发布时间】:2013-03-12 05:13:11 【问题描述】:

我正在从 apache2 迁移到 nginx。我不知道如何为 wordpress 重写这个 rewrite rules

这其实是我的配置文件

server 
        listen 80;    
        root /usr/share/nginx/blog.com/public_html;
        index index.html index.htm index.php;

        server_name blog.com www.blog.com;

        location / 
                try_files $uri $uri/ /index.html;

        

        location /doc/ 
                alias /usr/share/doc/;
                autoindex on;
                allow 127.0.0.1;
                allow ::1;
                deny all;
        

        location ~ .php$ 
                fastcgi_pass 127.0.0.1:9000;

                fastcgi_param  SCRIPT_FILENAME /usr/share/nginx/blog.com/public_html$fastcgi_script_name;
                fastcgi_index index.php;
                include fastcgi_params;
        


我正在使用 php5-fpm。

这是我想添加的规则:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule . /blog/index.php [L]
</IfModule>

# END WordPress

你能帮帮我吗?谢谢:)

【问题讨论】:

【参考方案1】:

你应该阅读http://wiki.nginx.org/WordPress

例如

    location /blog 
            try_files $uri $uri/ /blog/index.php?$args;
    

    location ~ \.php$ 
            fastcgi_split_path_info ^(/blog)(/.*)$;
    

【讨论】:

以上是关于从 apache 到 nginx:wordpress 重写规则的主要内容,如果未能解决你的问题,请参考以下文章