SprX
By:
SprX

How do I point another domain to a sub-folder?

February 12, 2017 393 views
DNS Apache LAMP Stack Ubuntu Ubuntu 16.04

I tried multiple tutorials online but up to no avail.
I want to point my new domain (eg newdomain.com) to a folder in /var/www/html/new/.

I bought the domain off namecheap.com and have set the custom DNS to dns1-3.digitalocean.com. Next, I made the DNS changes in the Networking area in the control panel. https://i.imgur.com/9tbsT4C.png

Afterwards, I created a Apache's VirtualHost in /etc/apacheites-available

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/mew
    ServerAlias   newdomain.com
    ServerName newdomain.com

        <Directory /var/www/html/new>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride all
            Order allow,deny
            allow from all
            Require all granted
    </Directory>

    <Proxy *>
        Order allow,deny
        Allow from all
    </Proxy>

    ProxyPass / http://IP-ADDRESS/new/ Keepalive=On
    ProxyPassReverse / http://IP-ADDRESS/new/
    ProxyPreserveHost On

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

After restarting Apache2, my primary + new domain doesn't seem to be loading at all.

1 Answer

@SprX

You don't need the ProxyPass configuration unless you're passing the request over to an address that uses a port other than 80/443. For example, if you were running a NodeJS app that was running on a port such as 2365, and you wanted it to respond on a port 80 (i.e. without having to attach a port to the URL), then you would use ProxyPass.

For a standard domain setup, you really only need

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /path/to/domain01.com
    ServerName domain01.com
    ServerAlias www.domain01.com

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <Directory /path/to/domain01.com>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride all
        Order allow,deny
        allow from all
        Require all granted
    </Directory>
</VirtualHost>

So if that's your base and you want domain02.com to point to /new in the same directory as your existing domain, you'd setup another server block and use something such as:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /path/to/domain01.com/new
    ServerName domain02.com
    ServerAlias www.domain02.com

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <Directory /path/to/domain01.com/new>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride all
        Order allow,deny
        allow from all
        Require all granted
    </Directory>
</VirtualHost>
  • Ah, working well! Thank you so much!

    I used to have applications that uses custom ports, thus using the ProxyPass configuration. Thought it was the same with application that uses the normal port 80.

    Thanks once again!

Have another answer? Share your knowledge.