Question

I'm not sure if this is even possible, but if so I'm looking for the best way to do it.

Say I want to host my blog for example.com on it's own EC2 instance, and I want the path to my blog to be example.com/blog

Is it possible to route all requests to example.com/blog/* to one instance, and all other requests to that domain elsewhere?

My web server is Apache.

Thanks!

Was it helpful?

OTHER TIPS

Certainly it's possible, but not with DNS nor with an ELB. The most common solution to this is to use a web server that issues a 301 or 302 redirect.

In your case, example.com would point to whatever the main site is. The web server (nginx or Apache httpd, perhaps) hosting example.com would have a redirect for example.com/blog/* that is found at another destination.

Here's an SO post on using Nginx for a redirect and for using Apache for a redirect.

Yes, but you would have to proxy your requests through an instance handling example.com. How you configure this depends on your web server.

Some examples on how to configure this:

Since you are using Apache2 Server, so you can achieve this very easily by creating a Virtual Host.

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/vchost1.com.conf

Create Virtual Configuration using the above command, it copies the complete code of content from the default file provided by the apache2 Server.

sudo nano /etc/apache2/sites-available/vchost1.com.conf

start configuring host & domain according to your requirements

<VirtualHost *:80>
    ServerAdmin admin@domain.com
    ServerName domain.com
    ServerAlias www.domain.com
    DocumentRoot /var/www/domain.com/public_html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

here also, you can multiple Virtual Host configurations in a single file, start configuring and enjoy hacking.

you can also multiple web applications in a single instance by using the same method and theis reference.

https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-18-04-quickstart

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top