多站点WordPress在Nginx中重写规则

前端之家收集整理的这篇文章主要介绍了多站点WordPress在Nginx中重写规则前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在尝试使用wordpressNginx运行多域博客安装.最后一步是在.htaccess(仅限apache)中为Web服务器配置一些重写规则.如何将其转换为Nginx重写规则?

RewriteEngine On
RewriteBase /

RewriteRule ^index\.PHP$- [L]

# uploaded files
RewriteRule ^files/(.+) wp-includes/ms-files.PHP?file=$1 [L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule . index.PHP [L]
最佳答案
nginx rewrite rules example for WordPress 3

server{
    server_name *.example.com;  
    listen 80;
    #on server block
    ##necessary if using a multi-site plugin
    server_name_in_redirect off;
    ##necessary if running Nginx behind a reverse-proxy
    port_in_redirect off;
    access_log /var/log/Nginx/example-com-access.log;

    location / {
        root   /var/www/example.com/wordpress;
        index  index.html index.htm index.PHP;
        rewrite ^.*/files/(.*)$/wp-includes/ms-files.PHP?file=$1 last;
        if (!-e $request_filename) {
            rewrite ^.+/?(/wp-.*) $1 last;
            rewrite ^.+/?(/.*\.PHP)$$1 last;
            rewrite ^(.+)$/index.PHP?q=$1 last;
        }
    }

    location ~* ^.+\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$
    {
        root /var/www/example.com/wordpress;
        rewrite ^/.*(/wp-.*/.*\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js))$$1 last;
        rewrite ^.*/files/(.*(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js))$/wp-includes/ms-files.PHP?file=$1 last;
        expires 30d;
        break;
    }

    location ~ wp\-.*\.PHP|wp\-admin|\.PHP${
        include /etc/Nginx/fastcgi_params;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.PHP;
        fastcgi_param  SCRIPT_FILENAME  /var/www/example.com/wordpress$fastcgi_script_name;
    }
}
原文链接:https://www.f2er.com/nginx/434860.html

猜你在找的Nginx相关文章