Please note, the ‘NameVirtualHost’ directive is already enabled by default on Ubuntu 16.04 and CentOS 7.<\/p>\n
Create virtual hosts in Apache for each domain\/subdomain. For example, create virtual hosts for domain1.com and domain2.com :<\/p>\n
vi \/etc\/apache2\/sites-available\/domain1.conf<\/pre>\n<VirtualHost *:80> \nDocumentRoot “\/var\/www\/html\/domain1” \nServerName domain1.com \nServerAlias www.domain1.com<\/p>\n
# enter other directives here, e.g. :<\/p>\n
<Directory \/var\/www\/html\/domain1\/> \nOptions FollowSymLinks \nAllowOverride All \nOrder allow,deny \nallow from all<\/p>\n
<\/Directory> \nErrorLog \/var\/log\/apache2\/domain1.com-error_log \nCustomLog \/var\/log\/apache2\/domain2.com-access_log common \n<\/VirtualHost><\/p>\n
vi \/etc\/apache2\/sites-available\/domain2.conf<\/pre>\n<VirtualHost *:80> \nDocumentRoot “\/var\/www\/html\/domain2” \nServerName domain2.com \nServerAlias www.domain2.com<\/p>\n
# enter other directives here \n<\/VirtualHost><\/p>\n
Enable ‘domain1.conf’ and ‘domain2.conf’ configurations in Apache using:<\/p>\n
ln -s \/etc\/apache2\/sites-available\/domain1.conf \/etc\/apache2\/sites-enabled\/domain1.conf\r\nln -s \/etc\/apache2\/sites-available\/domain2.conf \/etc\/apache2\/sites-enabled\/domain2.conf<\/pre>\nOr, use the a2ensite command to enable the ‘domain1.conf’ and ‘domain2.conf’ configurations in Apache:<\/p>\n
sudo a2ensite domain1.conf\r\nsudo a2ensite domain2.conf<\/pre>\nRestart Apache for the changes to take effect:<\/p>\n
service apache2 restart<\/pre>\nCentOS or Fedora: \nEdit the main Apache configuration file (\/etc\/httpd\/conf\/httpd.conf) and add virtual hosts at the end:<\/p>\n
vi \/etc\/httpd\/conf\/httpd.conf<\/pre>\n<VirtualHost *:80> \nDocumentRoot “\/var\/www\/html\/domain1” \nServerName domain1.com \nServerAlias www.domain1.com \n# enter other directives here \n<\/VirtualHost> \n<VirtualHost *:80> \nDocumentRoot “\/var\/www\/html\/domain2” \nServerName domain2.com \nServerAlias www.domain2.com \n# enter other directives here \n<\/VirtualHost><\/p>\n
Restart Apache for the changes to take effect:<\/p>\n
service httpd restart<\/pre>\nCreate \/var\/www\/html\/domain1 and \/var\/www\/html\/domain2 directories, then upload your websites to them.<\/p>\n
All website files have to be readable by the web server, so set a proper ownership:<\/p>\n
Ubuntu or Debian:<\/p>\n
chown www-data:www-data -R \/var\/www\/html\/domain*<\/pre>\nCentOS or Fedora:<\/p>\n
chown apache:apache -R \/var\/www\/html\/domain*<\/pre>\nNginx Server Blocks<\/h2>\n In order to configure server blocks in nginx to host multiple domains\/subdomains using a single IP address, log in to your server via SSH and install nginx:<\/p>\n
Ubuntu or Debian:<\/p>\n
apt-get update\r\napt-get install nginx<\/pre>\nCentOS or Fedora:<\/p>\n
yum update\r\nyum install nginx<\/pre>\nCreate a backup of the nginx configuration, then set up a server block for the first website:<\/p>\n
Ubuntu or Debian:<\/p>\n
Create a new nginx configuration for the first domain:<\/p>\n
vi \/etc\/nginx\/sites-available\/domain1.conf<\/pre>\nAdd the following lines to it:<\/p>\n
server {\r\n listen 80;\r\n\r\n server_name domain1.com;\r\n\r\n root \/var\/www\/html\/domain1.com;\r\n index index.html index.htm index.php;\r\n\r\n location \/ {\r\n try_files $uri $uri\/ =404;\r\n }\r\n\r\n# add other directives here;\r\n\r\n}<\/pre>\nCentOS or Fedora:<\/p>\n
Run the following commands:<\/p>\n
mkdir \/etc\/nginx\/sites-available\r\nmkdir \/etc\/nginx\/sites-enabled<\/pre>\nAdd the following lines to the main nginx configuration file (\/etc\/nginx\/nginx.conf) at the end of HTTP block:<\/p>\n
vi \/etc\/nginx\/nginx.conf<\/pre>\ninclude \/etc\/nginx\/sites-enabled\/*.conf;<\/pre>\nCreate a new nginx configuration file for the first website:<\/p>\n
vi \/etc\/nginx\/sites-available\/domain1.com<\/pre>\nserver {\r\n listen 80;\r\n server_name domain1.com;\r\n root \/var\/www\/html\/domain1.com\/;\r\n index index.html index.htm index.php;\r\n\r\n location \/ {\r\n try_files $uri $uri\/ =404;\r\n }\r\n\r\n# add other directives here;\r\n\r\n}<\/pre>\nEnable ‘domain1.conf’ configurations in nginx using:<\/p>\n
sudo ln -s \/etc\/nginx\/sites-available\/domain1.com \/etc\/nginx\/sites-enabled\/<\/pre>\nRestart nginx for the changes to take effect:<\/p>\n
service nginx restart<\/pre>\nUpload each website to the root directory specified in the nginx server block, for example:<\/p>\n
mkdir -p \/var\/www\/html\/domain1<\/pre>\nSet a proper ownership of website files, so they can be accessible by the nginx web server (e.g. www-data):<\/p>\n
chown -R www-data:www-data \/var\/www\/html\/domain1<\/pre>\nThat is it. Repeat the same procedure for each additional website.<\/p>\n
Please note, for each domain or subdomain you want to host on your server, you need to create an A record that points to your server’s IP address and once the DNS changes fully propagate throughout the Internet, your website visitors should be able to access your websites using a web browser.<\/p>\n
\nOf course, you don\u2019t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to set up multiple websites on one single IP address with Apache or Nginx for you. They are available 24\u00d77 and will take care of your request immediately.<\/p>\n
PS.<\/span><\/strong><\/span> If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.<\/p>\n","protected":false},"excerpt":{"rendered":"In this tutorial, we are going to provide you with step-by-step instructions on how to host multiple websites on one … <\/p>\n
Read More<\/a><\/p>\n","protected":false},"author":4,"featured_media":20912,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[37,49],"yoast_head":"\nHow to host multiple websites on one VPS - RoseHosting<\/title>\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\t \n\t \n\t \n \n \n \n \n \n\t \n\t \n\t \n