Ubuntu16.04 apache2 configure virtual host

The whole process:

First, let a domain name point to our server;
then, filter all domain names pointing to our server through the configuration file, and let them point to different directories.




1. First add the IP address of the current host and the virtual host name to be set in the "/etc/hosts" file:
eg: the current IP of my computer is 172.16.130.53, and I want to create a file named clb.alex.com For virtual domain name, add
"172.16.130.53
clb.alex.com" to the "/etc/hosts" file




2. There is "000-default.conf" in the "/etc/apache2/sites-available" directory, the lower one The Ubuntu version may be named "default",
copy the "000-default.conf" file, and name it as you want to define, such as "clb.conf" [note that it must have a ".conf" suffix]
Then modify the content:
do the following:
1) Add "ServerName clb.alex.com";
2) Modify "DocumentRoot /var/www" to the directory defined by yourself.



3.!!!!!important
    After saving the edited configuration file, the configuration needs to be enabled.
    $ sudo a2ensite demo.conf

4. Restart the apache server!

sudo /etc/init.d/apache2 restart

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326395876&siteId=291194637