🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## Server:192.168.211 ``` yum -y install httpd policycoreutils-python # policycoreutils-python 软件包提供 semanage 命令 cp /usr/share/doc/httpd/httpd-2.*/httpd-vhost.conf /etc/httpd/conf.d/ mkdir /var/www/virtual mkdir /web echo '<h1>html</h1>' > /var/www/html/index.html echo '<h1>virtual</h1>' > /var/www/virtual/index.html echo '<h1>web</h1>' > /web/index.html ``` ### 相同端口,不同域名 ``` vim /etc/httpd/conf.d/httpd-vhost.conf <VirtualHost *:80> DocumentRoot "/var/www/html" ServerName html.example.com </VirtualHost> <VirtualHost *:80> DocumentRoot "/var/www/virtual" ServerName virtual.example.com </VirtualHost> <VirtualHost *:80> DocumentRoot "/web" ServerName web.example.com </VirtualHost> <Directory "/web"> AllowOverride None Require all granted </Directory> ls -Zd /var/www/html drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /var/www/html semanage fcontext -a -t httpd_sys_content_t '/web(/.*)?' restrorecon -RFv /web restorecon reset /web context unconfined_u:object_r:default_t:s0->system_u:object_r:httpd_sys_content_t:s0 restorecon reset /web/index.html context unconfined_u:object_r:default_t:s0->system_u:object_r:httpd_sys_content_t:s0 firewall-cmd --permanent --add-port=80/tcp firewall-cmd --reload systemctl restart httpd ``` ### 相同ip,不同端口 ``` vim /etc/httpd/conf.d/httpd-vhost.conf <VirtualHost 192.168.1.211:80> DocumentRoot "/var/www/html" ServerName 192.168.1.211:80 </VirtualHost> <VirtualHost 192.168.1.211:808> DocumentRoot "/var/www/virtual" ServerName 192.168.1.211:808 </VirtualHost> <VirtualHost 192.168.1.211:8088> DocumentRoot "/web" ServerName 192.168.1.211:8088 </VirtualHost> <Directory "/web"> AllowOverride None Require all granted </Directory> semanage fcontext -a -t httpd_sys_content_t '/web(/.*)?' restrorecon -RFv /web 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 semanage port -a -t http_port_t -p tcp 808 semanage port -a -t http_port_t -p tcp 8088 firewall-cmd --permanent --add-port=80/tcp firewall-cmd --permanent --add-port=808/tcp firewall-cmd --permanent --add-port=8088/tcp firewall-cmd --reload systemctl restart httpd ``` ### 个人用户主页 ``` vim /etc/httpd/conf.d/userdir.conf #UserDir disable UserDir public_html useradd webmaster mkdir /home/webmaster/public_html echo '<h1>webmaster</h1>' > /home/webmaster/public_html/index.html chmod o+rx /home/webmaster/ getsebool -a | grep httpd ...... httpd_enable_cgi --> on httpd_enable_ftp_server --> off ! httpd_enable_homedirs --> off httpd_execmem --> off httpd_graceful_shutdown --> on httpd_manage_ipa --> off ...... setsebool -P httpd_enable_homedirs on firewall-cmd --permanent --add-port=80/tcp firewall-cmd --reload systemctl restart httpd ``` ## Desktop ### 修改 hosts 文件,通过浏览器访问对应域名或 ip:port hosts 文件追加如下内容 ``` 192.168.1.211 html.exampe.com virtual.example.com web.example.com ```