【问题标题】:Nginx - multiple WordPress sites in different subdirectories - /wp-admin redirect loopNginx - 不同子目录中的多个 WordPress 站点 - /wp-admin 重定向循环
【发布时间】:2017-04-18 17:15:08
【问题描述】:

我正在尝试使用 Nginx 在三个不同的目录中托管三个单独的 WordPress 站点。经过数小时的研究,我完全找不到允许我访问/wp-admin 和网站上各个页面的配置。

这是我目前拥有的:

server {
        listen 80;
        listen [::]:80 ipv6only=on;

        root /var/www;
        server_name my.ip.add.ress;

        location /wp1 {
            root /var/www/wp1;
            index index.php index.html index.htm;
            try_files $uri $uri/ /wp1/index.php?q=$args;
        }

        location /wp2 {
            root /var/www/wp2;
            index index.php index.html index.htm;
            try_files $uri $uri/ /wp2/index.php?q=$args;
        }

        location /wp3 {
            root /var/www/wp3;
            index index.php index.html index.htm;
            try_files $uri $uri/ /wp3/index.php?q=$args;
        }

        if (!-e $request_filename) {
            rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
            rewrite ^/[_0-9a-zA-Z-]+.*(/wp-admin/.*\.php)$ $1 last;
            rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
        }   

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
              root /usr/share/nginx/html;
        }

        location ~ \.php$ {

                try_files           $uri =404;

                fastcgi_split_path_info ^(.+\.php)(/.+)$;

                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;

                fastcgi_cache moodle;
                fastcgi_cache_valid 200 60m;

                fastcgi_read_timeout 3600;
        }

        # Cache static content
        location ~* .(jpg|jpeg|png|gif|ico|css|js)$ {
                expires 365d;
        }
}

当我尝试访问 /wp-admin 时,我的浏览器卡在了重定向循环中。使用 rewrite_log 不会产生任何输出。

【问题讨论】:

    标签: wordpress nginx


    【解决方案1】:

    在你的问题中,你有这个:

    root /var/www;
    ...
    location /wp1 {
        root /var/www/wp1;
        ...
    }
    

    /wp1/foo 的路径名被解析为/var/www/wp1/wp1/foo。请注意,您已在路径名中添加了第二个 /wp1/ 术语。

    location /wp1 内部,根不会改变。您不需要在每个位置内指定root,因为它仍然是root /var/www;,无论如何都会从外部块继承。

    删除行:

    root /var/www/wp1; 
    root /var/www/wp2; 
    root /var/www/wp3; 
    

    请参阅this document 了解更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-27
      • 2017-06-29
      • 2015-04-15
      • 1970-01-01
      • 2014-05-03
      • 1970-01-01
      • 2017-08-19
      相关资源
      最近更新 更多