linux 虚拟主机功能 —基于端口号同时运行多个网站

1、创建网站数据保存目录及首页数据保存目录

[root@PC1linuxprobe /]# mkdir -p /home/wwwroot/6111
[root@PC1linuxprobe /]# mkdir -p /home/wwwroot/6222
[root@PC1linuxprobe /]# echo port1 > /home/wwwroot/6111/index.html
[root@PC1linuxprobe /]# echo port2 > /home/wwwroot/6222/index.html

 

2、修改httpd服务主配置文件,写入基于端口号的网站数据信息

[root@PC1linuxprobe /]# vim /etc/httpd/conf/httpd.con
……
 40 #
 41 #Listen 12.34.56.78:80
 42 Listen 80
 43 Listen 6111
 44 Listen 6222
 45 
 46 #
 47 # Dynamic Shared Object (DSO) Support
……
112 # you might expect, make sure that you have specifically enabled it
113 # below.
114 #
115 <VirtualHost 192.168.10.10:6111>
116 DocumentRoot /home/wwwroot/6111
117 ServerName www.linuxprobe.com
118 <Directory /home/wwwroot/6111>
119 AllowOverride None
120 Require all granted
121 </Directory>
122 </VirtualHost>
123 <VirtualHost 192.168.10.10:6222>
124 DocumentRoot /home/wwwroot/6222
125 ServerName bbs.linuxprobe.com
126 <Directory /home/wwwroot/6222>
127 AllowOverride None
128 Require all granted
129 </Directory>
130 </VirtualHost>
131 #
132 # DocumentRoot: The directory out of which you will serve your
133 # documents. By default, all requests are taken from this directory, but
112 # you might expect, make sure that you have specifically enabled it
113 # below.
114 #
115 <VirtualHost 192.168.10.10:6111>
116 DocumentRoot /home/wwwroot/6111
117 ServerName www.linuxprobe.com
118 <Directory /home/wwwroot/6111>
119 AllowOverride None
120 Require all granted
121 </Directory>
122 </VirtualHost>
123 <VirtualHost 192.168.10.10:6222>
124 DocumentRoot /home/wwwroot/6222
125 ServerName bbs.linuxprobe.com
126 <Directory /home/wwwroot/6222>
127 AllowOverride None
128 Require all granted
129 </Directory>
130 </VirtualHost>
131 #
132 # DocumentRoot: The directory out of which you will serve your
133 # documents. By default, all requests are taken from this directory, but
………

 

3、查看并修改网站数据存储目录及首页数据目录SElinux上下文值

[root@PC1linuxprobe /]# ls -ldZ /var/www/html/
drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /var/www/html/
[root@PC1linuxprobe /]# ls -ldZ /home/wwwroot/
drwxr-xr-x. root root unconfined_u:object_r:home_root_t:s0 /home/wwwroot/
[root@PC1linuxprobe /]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot
[root@PC1linuxprobe /]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/6111
[root@PC1linuxprobe /]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/6111/*
[root@PC1linuxprobe /]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/6222
[root@PC1linuxprobe /]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/6222/*
[root@PC1linuxprobe /]# restorecon -Rv /home/wwwroot/
restorecon reset /home/wwwroot context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0
restorecon reset /home/wwwroot/6111 context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0
restorecon reset /home/wwwroot/6111/index.html context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0
restorecon reset /home/wwwroot/6222 context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0
restorecon reset /home/wwwroot/6222/index.html context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0

 

4、重启httpd服务

[root@PC1linuxprobe /]# systemctl restart httpd
Job for httpd.service failed. See 'systemctl status httpd.service' and 'journalctl -xn' for details.

 

5、查看服务端口

[root@PC1linuxprobe /]# semanage port -l | grep http
http_cache_port_t              tcp      8080, 8118, 8123, 10001-10010
http_cache_port_t              udp      3130
http_port_t                    tcp      80, 81, 443, 488, 8008, 8009, 8443, 9000
pegasus_http_port_t            tcp      5988
pegasus_https_port_t           tcp      5989

 

6、添加服务端口

[root@PC1linuxprobe /]# semanage port -a -t http_port_t -p tcp 6111 
[root@PC1linuxprobe /]# semanage port -a -t http_port_t -p tcp 6222
[root@PC1linuxprobe /]# semanage port -l | grep http
http_cache_port_t              tcp      8080, 8118, 8123, 10001-10010
http_cache_port_t              udp      3130
http_port_t                    tcp      6222, 6111, 80, 81, 443, 488, 8008, 8009, 8443, 9000
pegasus_http_port_t            tcp      5988
pegasus_https_port_t           tcp      5989

 

7、重启httpd服务

[root@PC1linuxprobe /]# systemctl restart httpd

 

8、测试(通过)

 

 

 

 

 

posted @ 2020-11-24 23:57  小鲨鱼2018  阅读(366)  评论(0编辑  收藏  举报