WordPress on a subdirectory with Rails unicorn app in the root

Hi everyone,

I have been trying to get this working since last two days. Site root is running a rails app without any problems. I haven't been able to figure out how to do rewrite rules for WordPress. I have installed Nginx, Php and everything. Blog is online and it doesn't have any styling. CSS files are giving 200 code, but still something is wrong with them. Images are giving 403 errors. Once that are not will look like this, http://www.zesty.co.uk/blog/wp-content/uploads/2013/03/Screen-Shot-2013-03-25-at-19.27.36.png

Following is how my current config file look like,

    upstream unicorn {  
    server unix:/tmp/unicorn.zesty.sock fail_timeout=0;  
server {   
   listen 80;   
   server_name zesty.co.uk;  

   location ^~ /blog/ {  
          root               /home/deployer/apps/zesty;  
          index  index.html index.htm index.php;  
          if (!-e $request_filename) {  
          rewrite  ^(.*)$  /blog/index.php?q=$1  last;  
          location /blog/.*+.(jpg|jpeg|gif|css|png|js|ico|htm|html)$ {  
              root /home/deployer/apps/zesty/blog;   
              access\_log off;   
              expires 30d;   
            include fastcgi_params;   
            fastcgi_index index.php;   
            fastcgi_param SCRIPT_FILENAME     $document_root$fastcgi_script_name;  
            fastcgi_pass   unix:/var/run/php5-fpm.sock;  

            location / {  
                 root /home/deployer/apps/zesty/current/public;  
                 if (!-f $request_filename) {  
                 proxy_pass   http://unicorn;  

I tried few things and the code is messed up a little. Any help to solve this will be appreciated.

Thanks Tharindu

Try changing following lines:

  location /blog/.*+.(jpg|jpeg|gif|css|png|js|ico|htm|html)$ {  
      root /home/deployer/apps/zesty/blog;   


      location /blog/.*+.(jpg|jpeg|gif|css|png|js|ico|htm|html)$ {  
          root /home/deployer/apps/zesty;   

Your config is messed.

In fact you can remove that line:

  root /home/deployer/apps/zesty/blog;   

root location will be inherited.

It didn't help Rahul. I really want to get this done. I don't know if it's ok to ask, can I hire you so you can have a good look at it? If so please give me a quote.

skype - live:tjosm Thanks

Please check my email reply. Sent you requested details.

Hi Rahul,

I finally figured it out. I've posted solution here, http://tjosm.com/3128/nginx-rewrite-rules-wordpress-subdirectory-ruby-rails-app/

Thanks for your help, you pointed me to right direction by saying my configs were a mess. After our little discussion, I wiped out whole config file and started fresh.

Glad to know that. :-)

You can further optimise config by using nginx's try_files directive. Just spend some more time on it. try_files is the way to go ahead! :-)

Thanks Rahul, I'll sure look into it.