10.5.1 \u57fa\u4e8eIP\u5730\u5740<\/strong><\/span><\/h6>\n\u5982\u679c\u4e00\u53f0\u670d\u52a1\u5668\u6709\u591a\u4e2aIP\u5730\u5740\uff0c\u800c\u4e14\u6bcf\u4e2aIP\u5730\u5740\u4e0e\u670d\u52a1\u5668\u4e0a\u90e8\u7f72\u7684\u6bcf\u4e2a\u7f51\u7ad9\u4e00\u4e00\u5bf9\u5e94\uff0c\u8fd9\u6837\u5f53\u7528\u6237\u8bf7\u6c42\u8bbf\u95ee\u4e0d\u540c\u7684IP\u5730\u5740\u65f6\uff0c\u4f1a\u8bbf\u95ee\u5230\u4e0d\u540c\u7f51\u7ad9\u7684\u9875\u9762\u8d44\u6e90\u3002\u800c\u4e14\uff0c\u6bcf\u4e2a\u7f51\u7ad9\u90fd\u6709\u4e00\u4e2a\u72ec\u7acb\u7684IP\u5730\u5740\uff0c\u8fd9\u5bf9\u641c\u7d22\u5f15\u64ce\u4f18\u5316\u4e5f\u5927\u6709\u88e8\u76ca\u3002\u56e0\u6b64\u4ee5\u8fd9\u79cd\u65b9\u5f0f\u63d0\u4f9b\u865a\u62df\u7f51\u7ad9\u4e3b\u673a\u529f\u80fd\u4e0d\u4ec5\u6700\u5e38\u89c1\uff0c\u800c\u4e14\u4e5f\u53d7\u5230\u4e86\u7f51\u7ad9\u7ad9\u957f\u7684\u6b22\u8fce\uff08\u5c24\u5176\u662f\u8349\u6839\u7ad9\u957f\uff09\u3002<\/p>\n
\u7b2c4\u7ae0\u548c\u7b2c9\u7ae0\u5206\u522b\u8bb2\u89e3\u4e86\u7528\u4e8e\u914d\u7f6e\u7f51\u7edc\u7684\u4e24\u79cd\u65b9\u6cd5\uff0c\u5927\u5bb6\u5728\u5b9e\u9a8c\u4e2d\u548c\u5de5\u4f5c\u4e2d\u53ef\u968f\u610f\u9009\u62e9\u3002\u5c31\u5f53\u524d\u7684\u5b9e\u9a8c\u6765\u8bb2\uff0c\u9700\u8981\u914d\u7f6e\u7684IP\u5730\u5740\u5982\u56fe10-14\u6240\u793a\u3002\u5728\u914d\u7f6e\u5b8c\u6bd5\u5e76\u91cd\u542f\u7f51\u7edc\u670d\u52a1\u4e4b\u540e\uff0c\u8bb0\u5f97\u68c0\u67e5\u7f51\u7edc\u7684\u8fde\u901a\u6027\uff0c\u786e\u4fdd3\u4e2aIP\u5730\u5740\u5747\u53ef\u6b63\u5e38\u8bbf\u95ee\uff0c\u5982\u56fe10-15\u6240\u793a\uff08\u8fd9\u5f88\u91cd\u8981\uff0c\u4e00\u5b9a\u8981\u6d4b\u8bd5\u597d\uff0c\u7136\u540e\u518d\u8fdb\u884c\u4e0b\u4e00\u6b65\uff09\u3002<\/p>\n
<\/p>\n
\u56fe10-14\u00a0 \u4f7f\u7528nmtui\u547d\u4ee4\u914d\u7f6e\u7f51\u7edc\u53c2\u6570<\/p>\n
[root@linuxprobe ~]# nmcli connection up ens160 \r\nConnection successfully activated (D-Bus active path: \/org\/freedesktop\/NetworkManager\/ActiveConnection\/6)<\/pre>\n<\/p>\n
\u56fe10-15\u00a0 \u5206\u522b\u68c0\u67e53\u4e2aIP\u5730\u5740\u7684\u8fde\u901a\u6027<\/p>\n
\u7b2c1\u6b65<\/strong>\uff1a\u5206\u522b\u5728\/home\/wwwroot\u4e2d\u521b\u5efa\u7528\u4e8e\u4fdd\u5b58\u4e0d\u540c\u7f51\u7ad9\u6570\u636e\u76843\u4e2a\u76ee\u5f55\uff0c\u5e76\u5411\u5176\u4e2d\u5206\u522b\u5199\u5165\u7f51\u7ad9\u7684\u9996\u9875\u6587\u4ef6\u3002\u6bcf\u4e2a\u9996\u9875\u6587\u4ef6\u4e2d\u5e94\u6709\u660e\u786e\u533a\u5206\u4e0d\u540c\u7f51\u7ad9\u5185\u5bb9\u7684\u4fe1\u606f\uff0c\u65b9\u4fbf\u7a0d\u540e\u80fd\u66f4\u76f4\u89c2\u5730\u68c0\u67e5\u6548\u679c\u3002<\/p>\n[root@linuxprobe ~]# mkdir -p \/home\/wwwroot\/10\r\n[root@linuxprobe ~]# mkdir -p \/home\/wwwroot\/20\r\n[root@linuxprobe ~]# mkdir -p \/home\/wwwroot\/30\r\n[root@linuxprobe ~]# echo \"IP:192.168.10.10\" > \/home\/wwwroot\/10\/index.html\r\n[root@linuxprobe ~]# echo \"IP:192.168.10.20\" > \/home\/wwwroot\/20\/index.html\r\n[root@linuxprobe ~]# echo \"IP:192.168.10.30\" > \/home\/wwwroot\/30\/index.html\r\n<\/pre>\n\u7b2c2\u6b65<\/strong>\uff1a\u4ecehttpd\u670d\u52a1\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u5927\u7ea6\u7b2c132\u884c\u5904\u5f00\u59cb\uff0c\u5206\u522b\u8ffd\u52a0\u5199\u51653\u4e2a\u57fa\u4e8eIP\u5730\u5740\u7684\u865a\u62df\u4e3b\u673a\u7f51\u7ad9\u53c2\u6570\uff0c\u7136\u540e\u4fdd\u5b58\u5e76\u9000\u51fa\u3002\u8bb0\u5f97\u9700\u8981\u91cd\u542fhttpd\u670d\u52a1\uff0c\u8fd9\u4e9b\u914d\u7f6e\u624d\u751f\u6548\u3002<\/p>\n\n
[root@linuxprobe ~]# vim \/etc\/httpd\/conf\/httpd.conf\r\n\u2026\u2026\u2026\u2026\u2026\u2026\u7701\u7565\u90e8\u5206\u8f93\u51fa\u4fe1\u606f\u2026\u2026\u2026\u2026\u2026\u2026\r\n132 <VirtualHost 192.168.10.10><\/strong>\r\n133 DocumentRoot \/home\/wwwroot\/10\r\n134 ServerName q13zd.cn\r\n135 <Directory \/home\/wwwroot\/10>\r\n136 AllowOverride None\r\n137 Require all granted\r\n138 <\/Directory>\r\n139 <\/VirtualHost><\/strong>\r\n\u00a0\u00a0\r\n140 <VirtualHost 192.168.10.20><\/strong>\r\n141 DocumentRoot \/home\/wwwroot\/20\r\n142 ServerName www.linuxcool.com\r\n143 <Directory \/home\/wwwroot\/20>\r\n144 AllowOverride None\r\n145 Require all granted\r\n146 <\/Directory>\r\n147 <\/VirtualHost><\/strong>\r\n\u00a0\u00a0\r\n148 <VirtualHost 192.168.10.30><\/strong>\r\n149 DocumentRoot \/home\/wwwroot\/30\r\n150 ServerName www.linuxdown.com\r\n151 <Directory \/home\/wwwroot\/30>\r\n152 AllowOverride None\r\n153 Require all granted\r\n154 <\/Directory>\r\n155 <\/VirtualHost><\/strong>\r\n\u2026\u2026\u2026\u2026\u2026\u2026\u7701\u7565\u90e8\u5206\u8f93\u51fa\u4fe1\u606f\u2026\u2026\u2026\u2026\u2026\u2026\r\n[root@linuxprobe ~]# systemctl restart httpd\r\n<\/pre>\n<\/div>\n\u7b2c3\u6b65<\/strong>\uff1a\u6b64\u65f6\u8bbf\u95ee\u7f51\u7ad9\uff0c\u5219\u4f1a\u770b\u5230httpd\u670d\u52a1\u7a0b\u5e8f\u7684\u9ed8\u8ba4\u9996\u9875\u9762\u4e2d\u663e\u793a\u201c\u6743\u9650\u4e0d\u8db3\u201d\u3002\u5927\u5bb6\u73b0\u5728\u5e94\u8be5\u7acb\u523b\u5c31\u53cd\u5e94\u8fc7\u6765\u2014\u8fd9\u662fSELinux\u5728\u6363\u9b3c\u3002\u7531\u4e8e\u5f53\u524d\u7684\/home\/wwwroot\u76ee\u5f55\u53ca\u91cc\u9762\u7684\u7f51\u7ad9\u6570\u636e\u76ee\u5f55\u7684SELinux\u5b89\u5168\u4e0a\u4e0b\u6587\u4e0e\u7f51\u7ad9\u670d\u52a1\u4e0d\u543b\u5408\uff0c\u56e0\u6b64httpd\u670d\u52a1\u7a0b\u5e8f\u65e0\u6cd5\u83b7\u53d6\u5230\u8fd9\u4e9b\u7f51\u7ad9\u6570\u636e\u76ee\u5f55\u3002\u6211\u4eec\u9700\u8981\u624b\u52a8\u628a\u65b0\u7684\u7f51\u7ad9\u6570\u636e\u76ee\u5f55\u7684SELinux\u5b89\u5168\u4e0a\u4e0b\u6587\u8bbe\u7f6e\u6b63\u786e\uff08\u89c1\u524d\u6587\u7684\u5b9e\u9a8c\uff09\uff0c\u5e76\u4f7f\u7528restorecon\u547d\u4ee4\u8ba9\u65b0\u8bbe\u7f6e\u7684SELinux\u5b89\u5168\u4e0a\u4e0b\u6587\u7acb\u5373\u751f\u6548\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u7acb\u5373\u770b\u5230\u7f51\u7ad9\u7684\u8bbf\u95ee\u6548\u679c\u4e86\uff0c\u5982\u56fe10-16\u6240\u793a\u3002<\/p>\n[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t \/home\/wwwroot\r\n[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t \/home\/wwwroot\/10\r\n[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t \/home\/wwwroot\/10\/*\r\n[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t \/home\/wwwroot\/20\r\n[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t \/home\/wwwroot\/20\/*\r\n[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t \/home\/wwwroot\/30\r\n[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t \/home\/wwwroot\/30\/*\r\n[root@linuxprobe ~]# restorecon -Rv \/home\/wwwroot\r\nRelabeled \/home\/wwwroot from unconfined_u:object_r:user_home_dir_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0\r\nRelabeled \/home\/wwwroot\/10 from unconfined_u:object_r:user_home_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0\r\nRelabeled \/home\/wwwroot\/10\/index.html from unconfined_u:object_r:user_home_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0\r\nRelabeled \/home\/wwwroot\/20 from unconfined_u:object_r:user_home_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0\r\nRelabeled \/home\/wwwroot\/20\/index.html from unconfined_u:object_r:user_home_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0\r\nRelabeled \/home\/wwwroot\/30 from unconfined_u:object_r:user_home_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0\r\nRelabeled \/home\/wwwroot\/30\/index.html from unconfined_u:object_r:user_home_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0\r\n[root@linuxprobe ~]# firefox<\/pre>\n<\/p>\n
\u56fe10-16\u00a0 \u57fa\u4e8e\u4e0d\u540c\u7684IP\u5730\u5740\u8bbf\u95ee\u865a\u62df\u4e3b\u673a\u7f51\u7ad9<\/p>\n
10.5.2 \u57fa\u4e8e\u4e3b\u673a\u57df\u540d<\/span><\/strong><\/h6>\n\u5f53\u670d\u52a1\u5668\u65e0\u6cd5\u4e3a\u6bcf\u4e2a\u7f51\u7ad9\u90fd\u5206\u914d\u4e00\u4e2a\u72ec\u7acbIP\u5730\u5740\u7684\u65f6\u5019\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u8ba9Apache\u81ea\u52a8\u8bc6\u522b\u7528\u6237\u8bf7\u6c42\u7684\u57df\u540d\uff0c\u4ece\u800c\u6839\u636e\u4e0d\u540c\u7684\u57df\u540d\u8bf7\u6c42\u6765\u4f20\u8f93\u4e0d\u540c\u7684\u5185\u5bb9\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\u7684\u914d\u7f6e\u66f4\u52a0\u7b80\u5355\uff0c\u53ea\u9700\u8981\u4fdd\u8bc1\u4f4d\u4e8e\u751f\u4ea7\u73af\u5883\u4e2d\u7684\u670d\u52a1\u5668\u4e0a\u6709\u4e00\u4e2a\u53ef\u7528\u7684IP\u5730\u5740\uff08\u8fd9\u91cc\u4ee5192.168.10.10\u4e3a\u4f8b\uff09\u5c31\u53ef\u4ee5\u4e86\u3002\u7531\u4e8e\u5f53\u524d\u8fd8\u6ca1\u6709\u4ecb\u7ecd\u5982\u4f55\u914d\u7f6eDNS\u89e3\u6790\u670d\u52a1\uff0c\u56e0\u6b64\u9700\u8981\u624b\u52a8\u5b9a\u4e49IP\u5730\u5740\u4e0e\u57df\u540d\u4e4b\u95f4\u7684\u5bf9\u5e94\u5173\u7cfb\u3002\/etc\/hosts\u662fLinux\u7cfb\u7edf\u4e2d\u7528\u4e8e\u5f3a\u5236\u628a\u67d0\u4e2a\u4e3b\u673a\u57df\u540d\u89e3\u6790\u5230\u6307\u5b9aIP\u5730\u5740\u7684\u914d\u7f6e\u6587\u4ef6\u3002\u7b80\u5355\u6765\u8bf4\uff0c\u53ea\u8981\u8fd9\u4e2a\u6587\u4ef6\u914d\u7f6e\u6b63\u786e\uff0c\u5373\u4f7f\u7f51\u7edc\u53c2\u6570\u4e2d\u6ca1\u6709DNS\u4fe1\u606f\u4e5f\u4f9d\u7136\u80fd\u591f\u5c06\u57df\u540d\u89e3\u6790\u4e3a\u67d0\u4e2aIP\u5730\u5740\u3002<\/p>\n
\u7b2c1\u6b65<\/strong>\uff1a\u624b\u52a8\u5b9a\u4e49IP\u5730\u5740\u4e0e\u57df\u540d\u4e4b\u95f4\u5bf9\u5e94\u5173\u7cfb\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u4fdd\u5b58\u5e76\u9000\u51fa\u540e\u4f1a\u7acb\u5373\u751f\u6548\u3002\u53ef\u4ee5\u901a\u8fc7\u5206\u522bping\u8fd9\u4e9b\u57df\u540d\u6765\u9a8c\u8bc1\u57df\u540d\u662f\u5426\u5df2\u7ecf\u6210\u529f\u89e3\u6790\u4e3aIP\u5730\u5740\u3002<\/p>\n[root@linuxprobe ~]# vim \/etc\/hosts\r\n127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4\r\n::1 localhost localhost.localdomain localhost6 localhost6.localdomain6\r\n192.168.10.10 q13zd.cn www.linuxcool.com www.linuxdown.com<\/strong>\r\n[root@linuxprobe ~]# ping -c 4 q13zd.cn\r\nPING q13zd.cn (192.168.10.10) 56(84) bytes of data.\r\n64 bytes from q13zd.cn (192.168.10.10): icmp_seq=1 ttl=64 time=0.070 ms\r\n64 bytes from q13zd.cn (192.168.10.10): icmp_seq=2 ttl=64 time=0.077 ms\r\n64 bytes from q13zd.cn (192.168.10.10): icmp_seq=3 ttl=64 time=0.061 ms\r\n64 bytes from q13zd.cn (192.168.10.10): icmp_seq=4 ttl=64 time=0.069 ms\r\n--- q13zd.cn ping statistics ---\r\n4 packets transmitted, 4 received, 0% packet loss, time 2999ms\r\nrtt min\/avg\/max\/mdev = 0.061\/0.069\/0.077\/0.008 ms\r\n[root@linuxprobe ~]# \r\n<\/pre>\n\u7b2c2\u6b65<\/strong>\uff1a\u5206\u522b\u5728\/home\/wwwroot\u4e2d\u521b\u5efa\u7528\u4e8e\u4fdd\u5b58\u4e0d\u540c\u7f51\u7ad9\u6570\u636e\u76843\u4e2a\u76ee\u5f55\uff0c\u5e76\u5411\u5176\u4e2d\u5206\u522b\u5199\u5165\u7f51\u7ad9\u7684\u9996\u9875\u6587\u4ef6\u3002\u6bcf\u4e2a\u9996\u9875\u6587\u4ef6\u4e2d\u5e94\u6709\u660e\u786e\u533a\u5206\u4e0d\u540c\u7f51\u7ad9\u5185\u5bb9\u7684\u4fe1\u606f\uff0c\u65b9\u4fbf\u7a0d\u540e\u80fd\u66f4\u76f4\u89c2\u5730\u68c0\u67e5\u6548\u679c\u3002<\/p>\n[root@linuxprobe ~]# mkdir -p \/home\/wwwroot\/linuxprobe\r\n[root@linuxprobe ~]# mkdir -p \/home\/wwwroot\/linuxcool\r\n[root@linuxprobe ~]# mkdir -p \/home\/wwwroot\/linuxdown\r\n[root@linuxprobe ~]# echo \"q13zd.cn\" > \/home\/wwwroot\/linuxprobe\/index.html\r\n[root@linuxprobe ~]# echo \"www.linuxcool.com\" > \/home\/wwwroot\/linuxcool\/index.html\r\n[root@linuxprobe ~]# echo \"www.linuxdown.com\" > \/home\/wwwroot\/linuxdown\/index.html\r\n<\/pre>\n\u7b2c3\u6b65<\/strong>\uff1a\u4ecehttpd\u670d\u52a1\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u5927\u7ea6\u7b2c132\u884c\u5904\u5f00\u59cb\uff0c\u5206\u522b\u8ffd\u52a0\u5199\u51653\u4e2a\u57fa\u4e8e\u4e3b\u673a\u540d\u7684\u865a\u62df\u4e3b\u673a\u7f51\u7ad9\u53c2\u6570\uff0c\u7136\u540e\u4fdd\u5b58\u5e76\u9000\u51fa\u3002\u8bb0\u5f97\u9700\u8981\u91cd\u542fhttpd\u670d\u52a1\uff0c\u8fd9\u4e9b\u914d\u7f6e\u624d\u751f\u6548\u3002<\/p>\n[root@linuxprobe ~]# vim \/etc\/httpd\/conf\/httpd.conf\r\n\u2026\u2026\u2026\u2026\u2026\u2026\u7701\u7565\u90e8\u5206\u8f93\u51fa\u4fe1\u606f\u2026\u2026\u2026\u2026\u2026\u2026\r\n132 <VirtualHost 192.168.10.10><\/strong>\r\n133 Documentroot \/home\/wwwroot\/linuxprobe\r\n134 ServerName q13zd.cn\r\n135 <Directory \/home\/wwwroot\/linuxprobe>\r\n136 AllowOverride None\r\n137 Require all granted\r\n138 <\/Directory>\r\n139 <\/VirtualHost><\/strong>\r\n\u00a0\r\n140 <VirtualHost 192.168.10.10><\/strong>\r\n141 Documentroot \/home\/wwwroot\/linuxcool\r\n142 ServerName www.linuxcool.com\r\n143 <Directory \/home\/wwwroot\/linuxcool>\r\n144 AllowOverride None\r\n145 Require all granted\r\n146 <\/Directory>\r\n147 <\/VirtualHost><\/strong>\r\n\u00a0\r\n148 <VirtualHost 192.168.10.10><\/strong>\r\n149 Documentroot \/home\/wwwroot\/linuxdown\r\n150 ServerName www.linuxdown.com\r\n151 <Directory \/home\/wwwroot\/linuxdown>\r\n152 AllowOverride None\r\n153 Require all granted\r\n154 <\/Directory>\r\n155 <\/VirtualHost><\/strong>\r\n\u2026\u2026\u2026\u2026\u2026\u2026\u7701\u7565\u90e8\u5206\u8f93\u51fa\u4fe1\u606f\u2026\u2026\u2026\u2026\u2026\u2026\r\n[root@linuxprobe ~]# systemctl restart httpd<\/pre>\n\u7b2c4\u6b65<\/strong>\uff1a\u56e0\u4e3a\u5f53\u524d\u7684\u7f51\u7ad9\u6570\u636e\u76ee\u5f55\u8fd8\u662f\u5728\/home\/wwwroot\u76ee\u5f55\u4e2d\uff0c\u56e0\u6b64\u8fd8\u662f\u5fc5\u987b\u8981\u6b63\u786e\u8bbe\u7f6e\u7f51\u7ad9\u6570\u636e\u76ee\u5f55\u6587\u4ef6\u7684SELinux\u5b89\u5168\u4e0a\u4e0b\u6587\uff0c\u4f7f\u5176\u4e0e\u7f51\u7ad9\u670d\u52a1\u529f\u80fd\u76f8\u543b\u5408\u3002\u6700\u540e\u8bb0\u5f97\u7528restorecon\u547d\u4ee4\u8ba9\u65b0\u914d\u7f6e\u7684SELinux\u5b89\u5168\u4e0a\u4e0b\u6587\u7acb\u5373\u751f\u6548\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u7acb\u5373\u8bbf\u95ee\u5230\u865a\u62df\u4e3b\u673a\u7f51\u7ad9\u4e86\uff0c\u6548\u679c\u5982\u56fe10-17\u6240\u793a\u3002<\/p>\n[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t \/home\/wwwroot\r\n[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t \/home\/wwwroot\/linuxprobe\r\n[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t \/home\/wwwroot\/linuxprobe\/*\r\n[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t \/home\/wwwroot\/linuxcool\r\n[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t \/home\/wwwroot\/linuxcool\/*\r\n[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t \/home\/wwwroot\/linuxdown\r\n[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t \/home\/wwwroot\/linuxdown\/*\r\n[root@linuxprobe ~]# restorecon -Rv \/home\/wwwroot\r\nRelabeled \/home\/wwwroot from unconfined_u:object_r:user_home_dir_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0\r\nRelabeled \/home\/wwwroot\/linuxprobe from unconfined_u:object_r:user_home_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0\r\nRelabeled \/home\/wwwroot\/linuxprobe\/index.html from unconfined_u:object_r:user_home_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0\r\nRelabeled \/home\/wwwroot\/linuxcool from unconfined_u:object_r:user_home_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0\r\nRelabeled \/home\/wwwroot\/linuxcool\/index.html from unconfined_u:object_r:user_home_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0\r\nRelabeled \/home\/wwwroot\/linuxdown from unconfined_u:object_r:user_home_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0\r\nRelabeled \/home\/wwwroot\/linuxdown\/index.html from unconfined_u:object_r:user_home_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0\r\n[root@linuxprobe ~]# firefox \r\n<\/pre>\n<\/p>\n
\u56fe10-17\u00a0 \u57fa\u4e8e\u4e3b\u673a\u57df\u540d\u8bbf\u95ee\u865a\u62df\u4e3b\u673a\u7f51\u7ad9<\/p>\n
10.5.3 \u57fa\u4e8e\u7aef\u53e3\u53f7<\/span><\/strong><\/h6>\n\u57fa\u4e8e\u7aef\u53e3\u53f7\u7684\u865a\u62df\u4e3b\u673a\u529f\u80fd\u53ef\u4ee5\u8ba9\u7528\u6237\u901a\u8fc7\u6307\u5b9a\u7684\u7aef\u53e3\u53f7\u6765\u8bbf\u95ee\u670d\u52a1\u5668\u4e0a\u7684\u7f51\u7ad9\u8d44\u6e90\u3002\u5728\u4f7f\u7528Apache\u914d\u7f6e\u865a\u62df\u7f51\u7ad9\u4e3b\u673a\u529f\u80fd\u65f6\uff0c\u57fa\u4e8e\u7aef\u53e3\u53f7\u7684\u914d\u7f6e\u65b9\u5f0f\u662f\u6700\u590d\u6742\u7684\u3002\u56e0\u6b64\u6211\u4eec\u4e0d\u4ec5\u8981\u8003\u8651httpd\u670d\u52a1\u7a0b\u5e8f\u7684\u914d\u7f6e\u56e0\u7d20\uff0c\u8fd8\u9700\u8981\u8003\u8651\u5230SELinux\u670d\u52a1\u5bf9\u65b0\u5f00\u8bbe\u7aef\u53e3\u7684\u76d1\u63a7\u3002\u4e00\u822c\u6765\u8bf4\uff0c\u4f7f\u752880\u3001443\u30018080\u7b49\u7aef\u53e3\u53f7\u6765\u63d0\u4f9b\u7f51\u7ad9\u8bbf\u95ee\u670d\u52a1\u662f\u6bd4\u8f83\u5408\u7406\u7684\uff0c\u5982\u679c\u4f7f\u7528\u5176\u4ed6\u7aef\u53e3\u53f7\u5219\u4f1a\u53d7\u5230SELinux\u670d\u52a1\u7684\u9650\u5236\u3002<\/p>\n
\u5728\u63a5\u4e0b\u6765\u7684\u5b9e\u9a8c\u4e2d\uff0c\u6211\u4eec\u4e0d\u4f46\u8981\u8003\u8651\u5230\u76ee\u5f55\u4e0a\u5e94\u7528\u7684SELinux\u5b89\u5168\u4e0a\u4e0b\u6587\u7684\u9650\u5236\uff0c\u8fd8\u9700\u8981\u8003\u8651SELinux\u57df\u5bf9httpd\u670d\u52a1\u7a0b\u5e8f\u7684\u7ba1\u63a7\u3002<\/p>\n
\u7b2c1\u6b65<\/strong>\uff1a\u5206\u522b\u5728\/home\/wwwroot\u4e2d\u521b\u5efa\u7528\u4e8e\u4fdd\u5b58\u4e0d\u540c\u7f51\u7ad9\u6570\u636e\u76843\u4e2a\u76ee\u5f55\uff0c\u5e76\u5411\u5176\u4e2d\u5206\u522b\u5199\u5165\u7f51\u7ad9\u7684\u9996\u9875\u6587\u4ef6\u3002\u6bcf\u4e2a\u9996\u9875\u6587\u4ef6\u4e2d\u5e94\u6709\u660e\u786e\u533a\u5206\u4e0d\u540c\u7f51\u7ad9\u5185\u5bb9\u7684\u4fe1\u606f\uff0c\u65b9\u4fbf\u7a0d\u540e\u80fd\u66f4\u76f4\u89c2\u5730\u68c0\u67e5\u6548\u679c\u3002<\/p>\n[root@linuxprobe ~]# mkdir -p \/home\/wwwroot\/6111\r\n[root@linuxprobe ~]# mkdir -p \/home\/wwwroot\/6222\r\n[root@linuxprobe ~]# mkdir -p \/home\/wwwroot\/6333\r\n[root@linuxprobe ~]# echo \"port:6111\" > \/home\/wwwroot\/6111\/index.html\r\n[root@linuxprobe ~]# echo \"port:6222\" > \/home\/wwwroot\/6222\/index.html\r\n[root@linuxprobe ~]# echo \"port:6333\" > \/home\/wwwroot\/6333\/index.html\r\n<\/pre>\n\u7b2c2\u6b65<\/strong>\uff1a\u5728httpd\u670d\u52a1\u914d\u7f6e\u6587\u4ef6\u7684\u7b2c46\u884c\uff5e48\u884c\u5206\u522b\u6dfb\u52a0\u7528\u4e8e\u76d1\u542c6111\u30016222\u548c6333\u7aef\u53e3\u7684\u53c2\u6570\u3002<\/p>\n[root@linuxprobe ~]# vim \/etc\/httpd\/conf\/httpd.conf\u00a0\r\n\u2026\u2026\u2026\u2026\u2026\u2026\u7701\u7565\u90e8\u5206\u8f93\u51fa\u4fe1\u606f\u2026\u2026\u2026\u2026\u2026\u2026 \r\n 37 # Listen: Allows you to bind Apache to specific IP addresses and\/or\r\n 38 # ports, instead of the default. See also the \r\n 39 # directive.\r\n 40 #\r\n 41 # Change this to Listen on specific IP addresses as shown below to \r\n 42 # prevent Apache from glomming onto all bound IP addresses.\r\n 43 #\r\n 44 #Listen 12.34.56.78:80\r\n 45 Listen 80\r\n 46 Listen 6111<\/strong>\r\n 47 Listen 6222\r\n<\/strong> 48 Listen 6333\r\n<\/strong>\u2026\u2026\u2026\u2026\u2026\u2026\u7701\u7565\u90e8\u5206\u8f93\u51fa\u4fe1\u606f\u2026\u2026\u2026\u2026\u2026\u2026\u00a0<\/strong><\/pre>\n\u7b2c3\u6b65<\/strong>\uff1a\u4ecehttpd\u670d\u52a1\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u5927\u7ea6\u7b2c134\u884c\u5904\u5f00\u59cb\uff0c\u5206\u522b\u8ffd\u52a0\u5199\u51653\u4e2a\u57fa\u4e8e\u7aef\u53e3\u53f7\u7684\u865a\u62df\u4e3b\u673a\u7f51\u7ad9\u53c2\u6570\uff0c\u7136\u540e\u4fdd\u5b58\u5e76\u9000\u51fa\u3002\u8bb0\u5f97\u9700\u8981\u91cd\u542fhttpd\u670d\u52a1\uff0c\u8fd9\u4e9b\u914d\u7f6e\u624d\u751f\u6548\u3002<\/p>\n[root@linuxprobe ~]# vim \/etc\/httpd\/conf\/httpd.conf\r\n\u2026\u2026\u2026\u2026\u2026\u2026\u7701\u7565\u90e8\u5206\u8f93\u51fa\u4fe1\u606f\u2026\u2026\u2026\u2026\u2026\u2026 \r\n134 <VirtualHost 192.168.10.10:6111><\/strong>\r\n135 DocumentRoot \/home\/wwwroot\/6111\r\n136 ServerName q13zd.cn\r\n137 <Directory \/home\/wwwroot\/6111>\r\n138 AllowOverride None\r\n139 Require all granted\r\n140 <\/Directory> \r\n141 <\/VirtualHost>\r\n<\/strong>\r\n142 <VirtualHost 192.168.10.10:6222><\/strong>\r\n143 DocumentRoot \/home\/wwwroot\/6222\r\n144 ServerName www.linuxcool.com\r\n145 <Directory \/home\/wwwroot\/6222>\r\n146 AllowOverride None\r\n147 Require all granted\r\n148 <\/Directory>\r\n149 <\/VirtualHost>\r\n\r\n<\/strong>150 <VirtualHost 192.168.10.10:6333><\/strong>\r\n151 DocumentRoot \/home\/wwwroot\/6333\r\n152 ServerName www.linuxdown.com\r\n153 <Directory \/home\/wwwroot\/6333>\r\n154 AllowOverride None\r\n155 Require all granted\r\n156 <\/Directory>\r\n157 <\/VirtualHost><\/strong>\r\n\u2026\u2026\u2026\u2026\u2026\u2026\u7701\u7565\u90e8\u5206\u8f93\u51fa\u4fe1\u606f\u2026\u2026\u2026\u2026\u2026\u2026<\/pre>\n\u7b2c4\u6b65<\/strong>\uff1a\u56e0\u4e3a\u6211\u4eec\u628a\u7f51\u7ad9\u6570\u636e\u76ee\u5f55\u5b58\u653e\u5728\/home\/wwwroot\u76ee\u5f55\u4e2d\uff0c\u56e0\u6b64\u8fd8\u662f\u5fc5\u987b\u8981\u6b63\u786e\u8bbe\u7f6e\u7f51\u7ad9\u6570\u636e\u76ee\u5f55\u6587\u4ef6\u7684SELinux\u5b89\u5168\u4e0a\u4e0b\u6587\uff0c\u4f7f\u5176\u4e0e\u7f51\u7ad9\u670d\u52a1\u529f\u80fd\u76f8\u543b\u5408\u3002\u6700\u540e\u8bb0\u5f97\u7528restorecon\u547d\u4ee4\u8ba9\u65b0\u914d\u7f6e\u7684SELinux\u5b89\u5168\u4e0a\u4e0b\u6587\u7acb\u5373\u751f\u6548\u3002<\/p>\n[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t \/home\/wwwroot\r\n[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t \/home\/wwwroot\/6111\r\n[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t \/home\/wwwroot\/6111\/*\r\n[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t \/home\/wwwroot\/6222\r\n[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t \/home\/wwwroot\/6222\/*\r\n[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t \/home\/wwwroot\/6333\r\n[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t \/home\/wwwroot\/6333\/*\r\n[root@linuxprobe ~]# restorecon -Rv \/home\/wwwroot\/\r\nRelabeled \/home\/wwwroot from unconfined_u:object_r:user_home_dir_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0\r\nRelabeled \/home\/wwwroot\/6111 from unconfined_u:object_r:user_home_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0\r\nRelabeled \/home\/wwwroot\/6111\/index.html from unconfined_u:object_r:user_home_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0\r\nRelabeled \/home\/wwwroot\/6222 from unconfined_u:object_r:user_home_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0\r\nRelabeled \/home\/wwwroot\/6222\/index.html from unconfined_u:object_r:user_home_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0\r\nRelabeled \/home\/wwwroot\/6333 from unconfined_u:object_r:user_home_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0\r\nRelabeled \/home\/wwwroot\/6333\/index.html from unconfined_u:object_r:user_home_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0\r\n[root@linuxprobe ~]# systemctl restart httpd\r\nJob for httpd.service failed because the control process exited with error code.\r\nSee \"systemctl status httpd.service\" and \"journalctl -xe\" for details.\r\n<\/pre>\n\u89c1\u9b3c\u4e86\uff01\u5728\u59a5\u5f53\u914d\u7f6ehttpd\u670d\u52a1\u7a0b\u5e8f\u548cSELinux\u5b89\u5168\u4e0a\u4e0b\u6587\u5e76\u91cd\u542fhttpd\u670d\u52a1\u540e\uff0c\u7adf\u7136\u51fa\u73b0\u62a5\u9519\u4fe1\u606f\u3002\u8fd9\u662f\u56e0\u4e3aSELinux\u670d\u52a1\u68c0\u6d4b\u52306111\u30016222\u548c6333\u7aef\u53e3\u539f\u672c\u4e0d\u5c5e\u4e8eApache\u670d\u52a1\u5e94\u8be5\u9700\u8981\u7684\u8d44\u6e90\uff0c\u4f46\u73b0\u5728\u5374\u4ee5httpd\u670d\u52a1\u7a0b\u5e8f\u7684\u540d\u4e49\u76d1\u542c\u4f7f\u7528\u4e86\uff0c\u6240\u4ee5SELinux\u4f1a\u62d2\u7edd\u4f7f\u7528Apache\u670d\u52a1\u4f7f\u7528\u8fd93\u4e2a\u7aef\u53e3\u3002\u53ef\u4ee5\u4f7f\u7528semanage\u547d\u4ee4\u67e5\u8be2\u5e76\u8fc7\u6ee4\u51fa\u6240\u6709\u4e0eHTTP\u534f\u8bae\u76f8\u5173\u4e14SELinux\u670d\u52a1\u5141\u8bb8\u7684\u7aef\u53e3\u5217\u8868\u3002<\/p>\n
[root@linuxprobe ~]# semanage port -l | grep http\r\nhttp_cache_port_t tcp 8080, 8118, 8123, 10001-10010\r\nhttp_cache_port_t udp 3130\r\nhttp_port_t tcp 80, 81, 443, 488, 8008, 8009, 8443, 9000<\/strong>\r\npegasus_http_port_t tcp 5988\r\npegasus_https_port_t tcp 5989\r\n<\/pre>\n\u7b2c5\u6b65<\/strong>\uff1aSELinux\u5141\u8bb8\u7684\u4e0eHTTP\u534f\u8bae\u76f8\u5173\u7684\u7aef\u53e3\u53f7\u4e2d\u9ed8\u8ba4\u6ca1\u6709\u5305\u542b6111\u30016222\u548c6333\uff0c\u56e0\u6b64\u9700\u8981\u5c06\u8fd93\u4e2a\u7aef\u53e3\u53f7\u624b\u52a8\u6dfb\u52a0\u8fdb\u53bb\u3002\u8be5\u64cd\u4f5c\u4f1a\u7acb\u5373\u751f\u6548\uff0c\u800c\u4e14\u5728\u7cfb\u7edf\u91cd\u542f\u8fc7\u540e\u4f9d\u7136\u6709\u6548\u3002\u8bbe\u7f6e\u597d\u540e\u518d\u91cd\u542fhttpd\u670d\u52a1\u7a0b\u5e8f\uff0c\u7136\u540e\u5c31\u53ef\u4ee5\u770b\u5230\u7f51\u9875\u5185\u5bb9\u4e86\uff0c\u7ed3\u679c\u5982\u56fe10-18\u6240\u793a\u3002<\/p>\n[root@linuxprobe ~]# semanage port -a -t http_port_t -p tcp 6111\r\n[root@linuxprobe ~]# semanage port -a -t http_port_t -p tcp 6222\r\n[root@linuxprobe ~]# semanage port -a -t http_port_t -p tcp 6333\r\n[root@linuxprobe ~]# semanage port -l | grep http\r\nhttp_cache_port_t tcp 8080, 8118, 8123, 10001-10010\r\nhttp_cache_port_t udp 3130\r\nhttp_port_t tcp 6333, 6222, 6111<\/strong>, 80, 81, 443, 488, 8008, 8009, 8443, 9000\r\npegasus_http_port_t tcp 5988\r\npegasus_https_port_t tcp 5989\r\n[root@linuxprobe ~]# systemctl restart httpd\r\n[root@linuxprobe ~]# firefox\r\n<\/pre>\n<\/p>\n
\u56fe10-18\u00a0 \u57fa\u4e8e\u7aef\u53e3\u53f7\u8bbf\u95ee\u865a\u62df\u4e3b\u673a\u7f51\u7ad9<\/p>\n