从 apache 到 nginx:wordpress 重写规则

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15568781/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 19:12:12  来源:igfitidea点击:

From apache to nginx: wordpress rewrite rule

wordpressapache.htaccessnginxpermalinks

提问by gaggina

I'm migrating from apache2 to nginx. I cant figure out how to to rewrite this rewrite rulesfor wordpress.

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

This is actually my configuration file

这实际上是我的配置文件

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;
        }

}

I'm using php5-fpm.

我正在使用 php5-fpm。

And this is the rule I would like to add :

这是我想补充的规则:

# 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

Can you please help me? Thanks :)

你能帮我么?谢谢 :)

回答by soju

You should read http://wiki.nginx.org/WordPress

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

e.g.

例如

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

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