首页 > 解决方案 > 冲突的 Nginx 重写规则

问题描述

寻找有关 Nginx 重写规则的帮助。我在同一台服务器上运行 Wordpress 和 MailWizz。Wordpress 安装在 root 中,MailWizz 安装在 root/mw 中。

WordPress 重写规则是:

  ## WordPress Perm links config ##               
    location / {
        try_files $uri $uri/ /index.php?$args;
    }
 
    ## Add trailing slash to */wp-admin requests.
    rewrite /wp-admin$ $scheme://$host$uri/ permanent;
 
    ## Deal with sitemap wordpress plugin urls ##
    rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.xml$ "/index.php?xml_sitemap=params=$2" last;
    rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.xml\.gz$ "/index.php?xml_sitemap=params=$2;zip=true" last;
    rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.html$ "/index.php?xml_sitemap=params=$2;html=true" last;
    rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.html.gz$ "/index.php?xml_sitemap=params=$2;html=true;zip=true" last;
 
    # Directives to send expires headers and turn off 404 error logging.
    location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
       access_log off; log_not_found off; expires max;
    }

MailWizz 重写规则是:

    if (!-e $request_filename){
    rewrite mw/customer/.* /mw/customer/index.php;
    }

    if (!-e $request_filename){
        rewrite mw/backend/.* /mw/backend/index.php;
    }

    if (!-e $request_filename){
        rewrite mw/api/.* /mw/api/index.php;
    }

    if (!-e $request_filename){
        rewrite ^(.*)$ /mw/index.php;
    }

每当我尝试将 WordPress 规则包含在 MailWizz 规则中时,都会导致 WordPress 永久链接出现问题。所以我正在寻找一种让两者共存的方法。它主要是破坏 WordPress 的 MailWizz 规则,MailWizz 继续正常工作。

有任何想法吗?

谢谢

标签: wordpressnginx

解决方案


推荐阅读