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

Here's my single Linux VPS setup:

  • A Rails app run by a Thin application server behind Nginx.
  • A WordPress blog run by lighttpd's spawn-fcgi behind the same Nginx server.

Here's what I want:

Both apps running under the same domain. All URIs starting with /blog or /wp-, or ending with .php, should go to the fastcgi server. Everything else should go to the Thin server.

Here's my problem:

My Rails app works fine. The front of my WordPress blog works fine. I cannot, however, access the WordPress admin panel (/wp-admin or /wp-login.php). The problem must be with my Nginx conf.

Here's my Nginx conf:

upstream myserver {
 server unix:/tmp/myserver.0.sock;
 server unix:/tmp/myserver.1.sock;
}

server {
    server_name myserver;

    root   /path/to/rails/app/public;
    index  index.html;

    access_log /path/to/rails/app/log/access.log;
    error_log /path/to/rails/app/log/error.log;

    <snip>

    location / {
        proxy_set_header  X-Real-IP  $remote_addr;
        proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect false;

        if (-f $document_root/cache$request_uri/index.html) {
           rewrite (.*) /cache$1/index.html break;
        }

        if (-f $document_root/cache$request_uri.html) {
           rewrite (.*) /cache$1.html break;
        } 

        if (!-f $request_filename) {
            proxy_pass http://myserver;
            break;
        }
    }

    location ~ /(blog|wp-).* {
        root /path/to/wordpress;
        index index.php;

        access_log /path/to/wordpress/log/access.log;
        error_log /path/to/wordpress/log/error.log;

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

    #
    # pass the PHP scripts to FastCGI server
    location ~ \.php$ {
        root /path/to/wordpress;
        index index.php;

        access_log /path/to/wordpress/log/access.log;
        error_log /path/to/wordpress/log/error.log;

        fastcgi_pass unix:/tmp/fcgi.sock;
        fastcgi_index index.php;
        include /etc/nginx/fastcgi_params;
        fastcgi_param SCRIPT_FILENAME /path/to/wordpress/$fastcgi_script_name;
    }
}

When I turn on debug logging to the WordPress error log. I never see a match for /wp-admin when I request it. That leads me to believe the request is being handled by the location /rule, which is intended for the Rails app. When I do request /wp-admin I'm prompted by the browser to "save as" some file named "download."

Note that assets under the wp-content directory are served up fine as they hit the location ~ /(blog|wp-).* rule (why doesn't /wp-admin hit there?!)

My Question:

What rules do I need to have my desired setup and be able to acces the WP admin panel?

Thanks in advance.

share|improve this question
    
I downloaded the file that I get prompted to save when I request /wp-admin and, as I suspected, it is /wp-admin/index.php. Why isn't that executing? –  Chris Dec 12 '10 at 14:43
    
For troubleshooting, rewrites add rewrite_log on; in your server configuration an change your error_log to something like ` error_log _path_to_error_log_file notice;` and post the results, please. –  Iñigo Sep 8 '11 at 11:12
add comment

2 Answers

up vote 1 down vote accepted

I found a work-around. I changed location ~ /(blog|wp-).* to location ~ /blog.* and started using /wp-admin/index.php in my request. Then I got what I wanted. I still haven't figured out the rule for having /wp-admin produce the same result as /wp-admin/index.php, but I can live without it. Everything else is working as expected.

share|improve this answer
add comment

The Nginx wiki article on Wordpress should help: http://wiki.nginx.org/Wordpress

You have the proper root and index so I'm guessing it's just the if checking being weird and try_files will help you out.

share|improve this answer
    
Thanks for the reply. The if checks I got from Nginx configs that I use on other apps of mine. They work fine for a "one app per domain" setup, so I don't think they are problematic. I think it's this case of having 2 apps on one domain that is making things difficult. Also, I don't think a request for /wp-admin is going to the location ~ /(blog|wp-).* block like I want it to. I think that because I never see debug logs for those requests. Why not? –  Chris Dec 11 '10 at 15:37
add comment

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.