1

I have an existing meteor application and am using nginx as my server, lets say at example.com

I want to add a wordpress blog, which should be accessed at example.com/blog

I also preferably want my blog to exist on it's own droplet (server) but if it needs to be on the same droplet (server) then it's ok.

How do I do this?

I have been able to get it to work with a different server block with a different server_name at blog.example.com. I also have gotten static files to be accessible under a sub directory at example.com/blog/index.html. This where everything exists on the same droplet (server).

But I can't get a wordpress application be accessible through example.com/blog.

EDIT:

What I ended up doing is creating a new server instance(droplet), configured it with LEMP stack and NGINX. It works if I try to access the IP.

Now, on my actual server, added a location block

location /blog {
    rewrite ^/blog/(.*)$ /$1 break;

    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header Host $host;
    proxy_pass http://wordpress-server-ip;
    proxy_redirect off;
}

My new problem is, that my blog is not able to load the .css files in chrome because, my proxy server is configured to https and wordpress loads the files over http. You can check this out at https://juerix.com/blog.

So I went into my wp-config file and changed the site and wordpress url https://juerix.com/blog. Didn't help.

4
  • droplet? What is it? Can you please also post your existing Nginx config? Nov 3, 2016 at 14:49
  • @Pothi A droplet is a virtual server on digital ocean, similar to an instance on AWS.
    – Tim
    Nov 3, 2016 at 19:01
  • Thanks Tim. @nupac... I also preferably want my blog to exist on it's own droplet (server) but if it needs to be on the same droplet (server) then it's ok. Your question has got the (correct) answer. If you want the alternative answer too, please post it as a new question such as Hosting a Wordpress Blog in different IP, but serve it using Nginx as sub-directory. serverfault.com/help/someone-answers . It is unfair to expect both answers using the same question. I know the alternative answer too. But, Tim's answer deserved to be selected as right answer! Nov 4, 2016 at 9:25
  • @Pothi Thanks for the advice. I have a new question as per your advice. It's here, serverfault.com/questions/813440/…
    – nupac
    Nov 6, 2016 at 6:21

1 Answer 1

1

This took me a while to work out. The key is in the try_files line.

# Default location to serve
location / {
  # If the file can't be found try adding a slash on the end - it might be
  # a directory the client is looking for. Then try the Wordpress blog URL
  # this might send a few requests to PHP that don't need to go that way
  try_files $uri $uri/ /blog/index.php?$args;

}

Here's another bit I found useful

# Add trailing slash to */wp-admin requests.
rewrite /blog/wp-admin$ $scheme://$host$uri/ permanent;

Here's another location block I used, just as an example

# Rate limit wp-login.php to help prevent brute force attacks
location = /blog/wp-login.php {
  # Next line applies the rate limit defined above
  limit_req zone=login burst=3;
  fastcgi_keep_conn on;

  fastcgi_pass php56-fpm;
  include        fastcgi_params;
  fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
  more_clear_headers "Cache-Control";
   more_clear_headers Server; more_clear_headers "Pragma"; more_clear_headers "Expires";

  # No caching
  more_clear_headers "Cache-Control";
  add_header Cache-Control "private, max-age=0, no-cache, no-store";
  more_clear_headers "Expires";
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .