使用 wordpress 作为 drupal 安装的子目录?

使用 wordpress 作为 drupal 安装的子目录?

我正在运行带有 NginX 0.7.65 的 Ubuntu 10.04。

我已将 Drupal 安装在根目录中,并且它与正确配置的 vhost 文件完美配合,但现在我想将 Wordpress 安装在同一个域的子目录中。当我访问 example.com/wordpress 时,会出现 404 错误,并由 Drupal 处理。这是我的 vhost 文件:

    server {
        server_name www.example.com example.com;
        access_log /srv/www/example.com/logs/access.log;
        error_log /srv/www/example.com/logs/error.log;
        root /srv/www/example.com/public_html;

        location = /favicon.ico {
                log_not_found off;
                access_log off;
        }

        location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
        }

        # This matters if you use drush
        location = /backup {
                deny all;
        }

        # Very rarely should these ever be accessed outside of your lan
        location ~* \.(txt|log)$ {
                allow 192.168.0.0/16;
                deny all;
        }

        location ~ \..*/.*\.php$ {
                return 403;
        }

        location / {
                # This is cool because no php is touched for static content
                try_files $uri @rewrite;
        }

        location @rewrite {
                # Some modules enforce no slash (/) at the end of the URL
                # Else this rewrite block wouldn't be needed (GlobalRedirect)
                rewrite ^/(.*)$ /index.php?q=$1;
        }

        location ~ \.php$ {
                include conf-inc.d/fastcgi.conf;
                track_uploads uploads 60s;
        }

        # The Nginx module wants ?X-Progress-ID query parameter so
        # that it report the progress of the upload through a GET
        # request. But the drupal form element makes use of clean
        # URLs in the POST.
        location ~ (.*)/x-progress-id:(\w*) {
                rewrite ^(.*)/x-progress-id:(\w*)  $1?X-Progress-ID=$2;
        }

        # Now the above rewrite must be matched by a location that
        # activates it and references the above defined upload
        # tracking zone.
        location ^~ /progress {
                report_uploads uploads;
        }

        # Fighting with ImageCache? This little gem is amazing.
        location ~ ^/sites/.*/files/imagecache/ {
                try_files $uri @rewrite;
        }

        # Catch image styles for D7 too.
        location ~ ^/sites/.*/files/styles/ {
                try_files $uri @rewrite;
        }

        location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                expires max;
                log_not_found off;
        }

        # Deny access to Apache .htaccess files.
        location ~ /\.ht {
                deny all;
        }

}

答案1

从以下答案中获取灵感SO 上的类似帖子

问题是这个 php-fallback 的位置指令

location / {
        # This is cool because no php is touched for static content
        try_files $uri @rewrite;
}

location @rewrite {
        # Some modules enforce no slash (/) at the end of the URL
        # Else this rewrite block wouldn't be needed (GlobalRedirect)
        rewrite ^/(.*)$ /index.php?q=$1;
}

使用此配置,您可以重写对 drupal index.php 的所有请求,包括您的 wordpress 文件。解决方案是定义一个位置块来处理 wordpress 的 php-fallback

location  /wordpress {
    index index.php index.html index.htm;
    try_files $uri $uri/ /wordpress/index.php;
}

在此位置,您将所有请求重写到 wordpress index.php。

相关内容