Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm running Ubuntu 10.04 with NginX 0.7.65.

I have Drupal installed in the root directory and it works perfectly with an appropriately configured vhost file, but now I would like to install Wordpress in a subdirectory on the same domain. When I go to example.com/wordpress, it results in a 404 error and is handled by Drupal. Here is my vhost file:

    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;
        }

}
share|improve this question
    
Do you know if Wordpress is properly installed at all? Plus can you get directly to some of the files e.g. example.com/wordpress/wp-content/themes/twentyeleven/style.css . You also might want to try asking this on wordpress.stackexchange.com –  icc97 Mar 6 '12 at 17:45

1 Answer 1

Get inspiration from answer at similar thread on SO

The problem is this location directive for 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;
}

With this configuration you rewrite all request to drupal index.php, including your wordpress files. The solution is defining one location block to handle php-fallback for wordpress

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

In this location you rewrite all request to wordpress index.php.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.