Setting Up Apache Virtual Hosts on Ubuntu 14.04 LTS

Virtual Hostin a IPAddressprovide service . if has in VPS IPAddress, is very has .

in this , let how to setting in Ubuntu 14.04 LTS Apacheserver setting Virtual Host. Note, this for Ubuntu14.04 32.

not can in Ubuntu or Ubuntu (can can process is ) .

Solution

in this , use Ubuntu 14.04 32 LTS, 2respectively “unixmen1.local” and “unixmen2.local”. respectively 192.168.1.250/24 and server.unixmen.local. can according to need .

Apacheserver

apacheserver , we we Ubuntuserver :


  1. sudo aptget update

then , command apachenetwork server :


  1. sudo aptget install apache2

apacheserver , let we via this URL http:// server IPAddress/ server is

, apacheserver already .

setting Virtual Host

1.directory

in , let we . , to 2respectively “unixmen1.local” and “unixmen2.local”.

a file data .

, let we unixmen1.localthis a directory :


  1. sudo mkdir p /var/www/unixmen1.local/public_html

, for unixmen2.locala directory :


  1. sudo mkdir p /var/www/unixmen2.local/public_html

2. setting all and Permission

directory in has roothas Permission. we need 2directory has user , not is rootuser .


  1. sudo chown R $USER:$USER /var/www/unixmen1.local/public_html/
  2. sudo chown R $USER:$USER /var/www/unixmen2.local/public_html/

$USER” Loginuser .

setting apachedirectory (/var/www) directory , each all can from directory file .


  1. sudo chmod R 755 /var/www/

, we some file network data to Permission and user .

4.

in , we . , let we unixmen1.locala .

unixmen1.locala ,


  1. sudo vi /var/www/unixmen1.local/public_html/index.html

the following :


  1.  
  2.  
  3. www.unixmen1.local
  4.  
  5.  
  6. Welcome To Unixmen1.local website

  7.  
  8.  

file .

, to .


  1. sudo vi /var/www/unixmen2.local/public_html/index.html

the following :


  1.  
  2.  
  3. www.unixmen2.local
  4.  
  5.  
  6. Welcome To Unixmen2.local website

  7.  
  8.  

file .

5. configuration file

, apachehas a file 000-default.conf. we will 000-default.conffile to we configuration file .


  1. sudo cp /etc/apache2/sitesavailable/000default.conf /etc/apache2/sitesavailable/unixmen1.local.conf
  2. sudo cp /etc/apache2/sitesavailable/000default.conf /etc/apache2/sitesavailable/unixmen2.local.conf

configuration file .conf.

in , unximen1.local.conffile .


  1. sudo vi /etc/apache2/sitesavailable/unixmen1.local.conf

in unixmen1 (: “#” can . ) .


  1. *:80>
  2. # The ServerName directive sets the request scheme, hostname and port that
  3. # the server uses to identify itself. This is used when creating
  4. # redirection URLs. In the context of virtual hosts, the ServerName
  5. # specifies what hostname must appear in the request's Host: header to
  6. # match this virtual host. For the default virtual host (this file) this
  7. # value is not decisive as it is used as a last resort host regardless.
  8. # However, you must set it for any further virtual host explicitly.
  9. #ServerName www.example.com
  10.  
  11. ServerAdmin [email protected]
  12. ServerName unixmen1.local
  13. ServerAlias www.unixmen1.local
  14. DocumentRoot /var/www/unixmen1.local/public_html
  15.  
  16. # Available loglevels: trace8, …, trace1, debug, info, notice, warn,
  17. # error, crit, alert, emerg.
  18. # It is also possible to configure the loglevel for particular
  19. # modules, e.g.
  20. #LogLevel info ssl:warn
  21.  
  22. ErrorLog ${APACHE_LOG_DIR}/error.log
  23. CustomLog ${APACHE_LOG_DIR}/access.log combined
  24.  
  25. # For most configuration files from conf-available/, which are
  26. # enabled or disabled at a global level, it is possible to
  27. # include a line for only one particular virtual host. For example the
  28. # following line enables the CGI configuration for this host only
  29. # after it has been globally disabled with "a2disconf".
  30. #Include conf-available/serve-cgi-bin.conf
  31.  

, file .


  1. sudo vi /etc/apache2/sitesavailable/unixmen2.local.conf

in unixmen2 .


  1. *:80>
  2. # The ServerName directive sets the request scheme, hostname and port that
  3. # the server uses to identify itself. This is used when creating
  4. # redirection URLs. In the context of virtual hosts, the ServerName
  5. # specifies what hostname must appear in the request's Host: header to
  6. # match this virtual host. For the default virtual host (this file) this
  7. # value is not decisive as it is used as a last resort host regardless.
  8. # However, you must set it for any further virtual host explicitly.
  9. #ServerName www.example.com
  10.  
  11. ServerAdmin [email protected]
  12. ServerName unixmen2.local
  13. ServerAlias www.unixmen2.local
  14. DocumentRoot /var/www/unixmen2.local/public_html
  15.  
  16. # Available loglevels: trace8, …, trace1, debug, info, notice, warn,
  17. # error, crit, alert, emerg.
  18. # It is also possible to configure the loglevel for particular
  19. # modules, e.g.
  20. #LogLevel info ssl:warn
  21.  
  22. ErrorLog ${APACHE_LOG_DIR}/error.log
  23. CustomLog ${APACHE_LOG_DIR}/access.log combined
  24.  
  25. # For most configuration files from conf-available/, which are
  26. # enabled or disabled at a global level, it is possible to
  27. # include a line for only one particular virtual host. For example the
  28. # following line enables the CGI configuration for this host only
  29. # after it has been globally disabled with "a2disconf".
  30. #Include conf-available/serve-cgi-bin.conf
  31.  

file , configuration (000.default.conf), then configuration , .


  1. sudo a2dissite 000default.conf
  2. sudo a2ensite unixmen1.local.conf
  3. sudo a2ensite unixmen2.local.conf

, apacheserver .


  1. sudo service apache2 restart

is . in , we configuration apachin we Ubuntuserver

Editor/etc/hostsfile ,


  1. sudo vi /etc/hosts

in file .


  1. 192.168.1.250 unixmen1.local
  2. 192.168.1.250 unixmen2.local

file .

http://unixmen1.local or http://unixmen2.local. will to we .

Unixmen1.local :

Unixmen2.local

if from system these , need in DNSserver . not , no and DNSserver , via system Test, .

Cheers!


via: http://www.unixmen.com/setup-virtual-hosts-apache-ubuntu-14-04-lts/

Leave a Comment

Your email address will not be published.