天天看點

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、測試(通過)

linux 虛拟主機功能 —基于端口号同時運作多個網站
linux 虛拟主機功能 —基于端口号同時運作多個網站
linux 虛拟主機功能 —基于端口号同時運作多個網站