Question

Nginx proxy_pass to Wordpress on Remote Server

I’m trying to set up a proxy to my Wordpress blog using proxy_pass but I’m getting some very strange behavior. My Wordpress blog is located at blog.example.com/blog/ and the website at www.example.com, I’d like the blog to appear at www.example.com/blog/. Here’s the code I have, which works for viewing the blog but not for any PHP scripts(logging in, wp-cron, etc all results in “No Input File Specified” error) on the blog:

location /blog/ {
    expires off;
    proxy_pass http://blog.example.com/blog/;
}

Here is the output in my nginx error log when trying to access the wp-admin page:

2015/02/08 14:28:33 [error] 20572#0: *594485 FastCGI sent in stderr: "Unable to open primary script: /home/user/www.example.com/public/blog/wp-login.php (No such file or directory)" while reading response header from upstream, client: 10.0.1.214, server: www.example.com, request: "GET /blog/wp-login.php?redirect_to=http%3A%2F%2Fblog.example.com%2Fblog%2Fwp-admin%2F&reauth=1 HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "www.example.com"

It appears that any PHP script is hitting my .php block:

location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
}

Any help is greatly appreciated.

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

This question was answered by @moncefhammou:

@beaudierman I actually fixed it with this. Don’t know if it’s the best way to do it tho. Thanks for you help btw :)

   location ~* ^((?!\/blog)(.+)\.php)$ {
           fastcgi_split_path_info ^(.+\.php)(/.+)$;
           fastcgi_pass unix:/var/run/php5-fpm.sock;
           fastcgi_index index.php;
           include fastcgi_params;
   }

View the original comment