Install Apache and configure virtual hosts under Linux

install apache

1. Installation: (httpd is the name of Apache in centos)

yum install httpd

2. Start:

service httpd start

3. Web page access port 80: 172.20.73.243   IP address of LINUX 

Check whether port 80 of the firewall is enabled:

netstat -anpl | grep http

4. If it is enabled, the firewall is blocking access, just close the firewall.

Service firewalld stop


Configure virtual hosts

1. View and edit the httpd.conf file

vim  /etc/httpd/conf/httpd.conf   

2. Search for virtual keywords

/virtual

3. Click the " i " key to enter below

<VirtualHost *:80>

ServerName www.imooc.test

DocumentRoot /data/www

</VirtualHost >

 

4. Restart Apache

service httpd restart   

5.  Create the data directory and the www subdirectory under data

mkdir -p /data/www    

6.  Create an index.html file and enter "Hello world" arbitrarily

vim index.html    

7. Modify the hosts file under the windows machine and run input C:\WINDOWS\system32\drivers\etc to find the hosts file and open it with Notepad, enter the IP address of LINUX 172.22.73.243 www.imooc.test 

 

Note: If the hosts file cannot be saved, you need to change the permissions of the file

Right-click the hosts file → Properties → Security → Edit → Find the current user → Check Full Control under Permissions → OK

You can save it later

 

8. Use a browser to visit www.imooc.test  , if you still view the page of Testing.123 . just enter

cd /etc/httpd/logs

Go to the Log folder to view the access_log file

 tail -f error_log

9.  View and edit the httpd.conf file

vim  /etc/httpd/conf/httpd.conf

<VirtualHost *:80>

ServerName www.imooc.test

DocumentRoot /data/www

<Directory "/data/www">                                       

     Options Indexes FollowSymLinks

     AllowOverride None

     Require all granted

</Directory>

</VirtualHost >

Note: The configuration needs to be consistent with the root directory /data/www

 

10. Then restart the server,

service httpd restart

11. If the previously entered information has not been accessed at this time, it is a system problem. Enter the command setenforce 0   to access it. This is only temporary. After entering vim /etc/selinux/config , set   SELINUX=disabled to make it permanent . closure    


Guess you like

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