一个域名下部署两个WordPress的Nginx伪静态配置

二级目录下部署WordPress的情形已经很常见,根目录往往是其他类型的CMS,网上伪静态配置方法非常多。

如果根目录也是WordPress,伪静态配置会有一定区别。遇到的实际应用场景是一个做SPA项目的后台,另一个做普通CMS网站,要求数据库隔离。

方法不唯一,仅供参考。

    root  /Users/pury/www;
    index  index.html index.htm index.php;

    location /二级目录名/ {
        if (-f $request_filename/index.html){
            rewrite (.*) $1/index.html break;
        }
        
        if (-f $request_filename/index.php){
            rewrite (.*) $1/index.php;
        }
        
        if (!-f $request_filename){
            rewrite (.*) /二级目录名/index.php;
        }
    }

    location / {
        if (-f $request_filename/index.html){
            rewrite (.*) $1/index.html break;
        }
        
        if (-f $request_filename/index.php){
            rewrite (.*) $1/index.php;
        }
        
        if (!-f $request_filename){
            rewrite (.*) /index.php;
        }
    }

注:location /二级目录名/要放在location /之前。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容