Linux basic service-------web service, virtual web host (theory + practice + command)

One, web service

Requirement: configure IP and hostname for two machines respectively, turn off selinux and firewall

Turn off selinux and firewall commands:

[root@A ~]# vim /etc/selinux/config
SELINUX=disabled  #将selinux设置成disabled,开机重启才能生效

[root@A ~]# setenforce 0  #暂时设置成宽松模式

[root@A ~]# getenforce  
Permissive

[root@A ~]# systemctl  stop firewalld.service #关闭防火墙

The configuration of server A:

[root@A ~]# yum -y install httpd  #下载httpd

[root@A ~]# systemctl restart httpd.service #启动服务

[root@A ~]# firefox  192.168.4.7 #出现测试界面即成功

[root@A ~]# echo  求关注,求点赞 > /var/www/html/index.html  #书写网页文件

[root@A ~]# curl 192.168.4.7  #A测试访问
求关注,求点赞

 

Client B test:

[root@B ~]# curl 192.168.4.7 #B测试访问
求关注,求点赞

Two, web server configuration

Steps: Install the package----->Configuration----->Enable service----->Test
Configuration file: /etc/httpd/conf/httpd.conf

DocumentRoot: The root directory of the web page file (/var/www/html) The path where the web page file is stored

1. Modify the root directory of web page files

[root@B ~]# vim /etc/httpd/conf/httpd.conf
119行 DocumentRoot "/var/www/myweb"  #修改路径

[root@B ~]# mkdir /var/www/myweb

[root@B ~]# echo 我要三连 > /var/www/myweb/index.html

[root@B ~]# systemctl  restart  httpd.service

[root@B ~]# curl  192.168.4.207
我要三连

Note: There is access control for the path of storing webpage files, access control for /var/www, allowing everyone to access; access control for /, denying everyone access.

2. Build a virtual web host

Multiple different web sites provided by the same server

Differentiation method: host-based virtual host
port-based virtual host
IP address-based virtual host

Configure a virtual site: configuration file path: /etc/httpd/conf.d/*.conf

Construction process (based on domain name):

[root@A ~]# vim /etc/httpd/conf.d/myweb.conf

[root@A ~]# cat /etc/httpd/conf.d/myweb.conf
<VirtualHost *:80>
        ServerName www.qq.com     #此站点的DNS名称
        DocumentRoot /var/www/qq  #此站点的网页根目录
</VirtualHost>
<VirtualHost *:80>
        ServerName www.baidu.com
        DocumentRoot /var/www/baidu
</VirtualHost>

[root@A ~]# mkdir /var/www/qq /var/www/baidu

[root@A ~]# echo myqq > /var/www/qq/index.html
[root@A ~]# echo mybaidu > /var/www/baidu/index.html

[root@A ~]# vim /etc/hosts

[root@A ~]# cat /etc/hosts |tail -1  #本机提供DNS域名解析
192.168.4.7 www.qq.com www.baidu.com

[root@A ~]# systemctl  restart  httpd  #重启httpd服务

A测试:
[root@A ~]# curl www.qq.com
myqq
[root@A ~]# curl www.baidu.com
mybaidu

B测试:
[root@B ~]# cat /etc/hosts |tail -1
192.168.4.7  www.qq.com www.baidu.com

[root@B ~]# curl www.qq.com
myqq

For those who don’t know how to configure ip address and yum, please see the IP here
:
https://blog.csdn.net/ring__wang/article/details/108585221
yum:
https://blog.csdn.net/ring__wang/article/details/ 108501308

Guess you like

Origin blog.csdn.net/ring__wang/article/details/108614691