2

I currently have web servers for a web application hosted on AWS and I am planning on launching a blog for the web application, which I plan on hosting from a DigitalOcean server (Nginx) due to its ease of maintenance and direct integration with Ghost CMS, which I will be using as my blog CMS. I am aware that through DNS records it is easy and simple to point a sub-domain to the DigitalOcean droplet to serve the blog from something like blog.example.com, but I am trying to have the blog accessed from a sub-directory in the parent domain (www.example.com/blog).

Would it be possible for me to achieve this sub-directory access by adjusting the revers proxy on the Nginx server? Is there a different way to architect this communication between the two servers?

Example:

User goes to www.example.com (AWS server loads page)

User goes to www.example.com/blog/new-post (DigitalOcean server loads page)

cphill
  • 197
  • 1
  • 1
  • 12

1 Answers1

1

That's rather simple, you just create an A record for www.example.com that returns the IP of your DigitalOcean server. Then you host the /blog site on the NginX running on that server. Then you create another A record for the second AWS webserver, for example ´webhost1.example.com` (this second DNS record isn't necessary, but it's the prover way to do it and makes it easier if you ever want to move that server and it's IP changes) and you configure NginX something like this:

server {
  listen 80;
  listen [::]:80;

  server_name example.com;

  location / {
      proxy_pass http://webhost1.exmaple.com/;
  }
  location /blog/ {
      [your normal location config here]
  }
}

Do note that this is untested, so there might be some syntax errors etc. The line to note is the proxy_pass. This tells NginX to pass proxy the request on to another server. You can also use this pass traffic to services running on other ports on the same host etc.

More details on NginX Reverse Proxy https://www.linode.com/docs/web-servers/nginx/use-nginx-reverse-proxy/

Stuggi
  • 3,506
  • 4
  • 19
  • 36