How to host multiple websites on Linode?

I have a Linode server hosting my portfolio. My portfolio was built with Rails 3 and deployed with Nginx and Capistrano. I have a user called deployer and here's my folder structure:

/home/deployer/apps/portfolio

I want to do something like

/home/deployer/apps
                   /portfolio
                   /otherapp

Right now I'm using a DNS for rafaelfragoso.com on the DNS tab And my Linode only have one IP address.

What changes do I need to make to host more than one website? Thanks!

5 Replies

If you want to have your Linode respond with different content when it is accessed by a different name (e.g., example.net), you need to set up "name-based virtual hosting." The nginx guides in the Linode library discuss this. You can find additional documentation by searching on that term.

@Vance:

If you want to have your Linode respond with different content when it is accessed by a different name (e.g., example.net), you need to set up "name-based virtual hosting." The nginx guides in the Linode library discuss this. You can find additional documentation by searching on that term.

I'll take a look.

Create a file under /etc/apache2/sites-available for each website you want. You could name the files by the domain, such as web1.example.com.

Add the following to the file, with the information changed for your website:

 <virtualhost *:80=""># Admin email, Server Name (domain name), and any aliases
  ServerAdmin webmaster@example.com
  ServerName  www.example.com
  ServerAlias example.com

  # Index file and Document Root (where the public files are located)
  DirectoryIndex index.html index.php
  DocumentRoot /home/example_user/public/example.com/public

  # Log file locations
  LogLevel warn
  ErrorLog  /home/example_user/public/example.com/log/error.log
  CustomLog /home/example_user/public/example.com/log/access.log combined</virtualhost> 

Then run````
sudo a2ensite web1.example.com

and then````
sudo service apache2 restart

Repeat this process for each web server directory and website you want to create.

I'm using Nginx as my web server.

I have the Linode's IP address and I have my domain (rafaelfragoso.com). I have my domain configured with nginx and passenger and everything works just fine. Now that I don't need the Linode's ip address to access my website, I want to use it for a different project like this:

/home/deployer/apps/rafaelfragoso.com/ (rafaelfragoso.com)
/home/deployer/apps/beta/ (xx.xx.xx.xx Linode's ip)

How can I accomplish that?

PS: I'm not using the sites-enabled/sites-available folders.

@rafaelfragosom:

I'm using Nginx as my web server.

I have the Linode's IP address and I have my domain (rafaelfragoso.com). I have my domain configured with nginx and passenger and everything works just fine. Now that I don't need the Linode's ip address to access my website, I want to use it for a different project like this:

/home/deployer/apps/rafaelfragoso.com/ (rafaelfragoso.com)
/home/deployer/apps/beta/ (xx.xx.xx.xx Linode's ip)

How can I accomplish that?

PS: I'm not using the sites-enabled/sites-available folders.

That can be accomplished by setting up a virtual host in Nginx, setting the server_name to your Linode's IP address. You'd then set the root to /home/deployer/apps/beta (or whatever you want to serve via the IP). I actually use that trick at home due to a bug in my router – I have remote management disabled, but it still displays the remote management page UNLESS I forward connections to my home server to give people a "Quit Spying On Me!" message :wink:

EDIT: Personally I think using sites-available/sites-enabled keeps things more organized, it makes it easier to enable/disable virtual hosts without deleting or moving them. Just my 1 cent.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct