kirby
By:
kirby

Point domain to a subfolder

September 9, 2014 12.8k views

I have a Drupal install as a sub folder on a droplet. I want to point the domain to this subfolder, ie. 111.111.111.11/drupal. How do I do this within Digital Ocean's control panel?

2 comments
  • What OS and WebServer are you using ?

  • You can't do it via DO control panel you have to point your domain name to the VPS IP address and than use software like Putty to SSH onto your VPS and setup configuration for your web server in your case I'm guessing apache2.

4 Answers

Hi Kirby,

To be technically true, you can't really "point a domain to a subfolder", put you can point a domain to an IP, as required by DNS to go on a website using a domain name instead of its IP.

So, in your situation, I much advise you to use Nginx as a reverse proxy, thanks to the use of server_name directives and document root location.

For example, if you want to host many websites on your VPS at IP 111.111.111.11, you can create as many folders you want in /var/www folder, and configure all your nginx virtualhosts to point the correct folder.

tree /var/www/
├── drupal_1
├── drupal_2

Once you have the following tree in your document root, you can use server_name directives to separate your drupal instances relied to a domain name with Nginx, with a configuration file of that kind :

server {
  listen *:80;         
  server_name drupal_1; 
  root /var/www/drupal_1;

  location / {
    try_files $uri $uri/index.html $uri.html @upstream;
  }

  location @upstream {
   your php-fpm configuration
  }
}
server {
  listen *:80;         
  server_name drupal_2; 
  root /var/www/drupal_2;

  location / {
    try_files $uri $uri/index.html $uri.html @upstream;
  }

  location @upstream {
   your php-fpm configuration
  }
}

Thanks to that kind of Nginx configuration, I guess that you will be able to do what you are looking for,

Hope this could help,

Best regards,

--
rustx

To expand rustx already detailed answer if you are not using Nginx the process is pretty similar in your domain manager/control panel simply point your AAAA record to your VPS IP Address and wait for it to refresh and start redirecting the domain to your VPS local folder than:

Open file: /etc/apache2/sites-enabled/000-default.conf

Or you can create a separate configuration file as you prefer I keep all my VHosts in one file. Once you have the configuration file open add new VHost configuration like so:

<VirtualHost *:80>
    DocumentRoot /var/www/subfolder
    ServerName www.domain.com
    ServerAlias domain.com
</VirtualHost>

Now go back to the folder: /etc/apache2 and open file: apache2.conf and add a new line:

ServerName www.domain.com

Save the file and restart your server using this command: service apache2 restart, the process is same across all OS the config folder locations tho can be different you can look those up.

@SterlingDuches That worked perfectly for me.
I just have one problem. When I type www.domain.com I get a " page not found ". Do you know how to solve this?

Thanks in advance.

@Joaobborges Setup your CNAME record to catch www too:
https://www.digitalocean.com/community/tutorials/how-to-set-up-a-host-name-with-digitalocean

(long tutorial, just scroll down to the CNAME section)

by Etel Sverdlov
This article walks you through setting up the DNS for your site. The tutorial includes steps to set up an A records, point your nameservers, and provides some information about MX records.
Have another answer? Share your knowledge.