Http 服务器

Server:192.168.211

1
2
3
4
5
6
7
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

相同端口,不同域名

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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,不同端口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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

个人用户主页

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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_anon_write --> off
httpd_builtin_scripting --> on
httpd_can_check_spam --> off
httpd_can_connect_ftp --> off
httpd_can_connect_ldap --> off
httpd_can_connect_mythtv --> off
httpd_can_connect_zabbix --> off
httpd_can_network_connect --> off
httpd_can_network_connect_cobbler --> off
httpd_can_network_connect_db --> off
httpd_can_network_memcache --> off
httpd_can_network_relay --> off
httpd_can_sendmail --> off
httpd_dbus_avahi --> off
httpd_dbus_sssd --> off
httpd_dontaudit_search_dirs --> off
httpd_enable_cgi --> on
httpd_enable_ftp_server --> off
! httpd_enable_homedirs --> off
httpd_execmem --> off
httpd_graceful_shutdown --> on
httpd_manage_ipa --> off
httpd_mod_auth_ntlm_winbind --> off
httpd_mod_auth_pam --> off
httpd_read_user_content --> off
httpd_run_ipa --> off
httpd_run_preupgrade --> off
httpd_run_stickshift --> off
httpd_serve_cobbler_files --> off
httpd_setrlimit --> off
httpd_ssi_exec --> off
httpd_sys_script_anon_write --> off
httpd_tmp_exec --> off
httpd_tty_comm --> off
httpd_unified --> off
httpd_use_cifs --> off
httpd_use_fusefs --> off
httpd_use_gpg --> off
httpd_use_nfs --> off
httpd_use_openstack --> off
httpd_use_sasl --> off
httpd_verify_dns --> 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 文件追加如下内容

1
192.168.1.211	html.exampe.com	virtual.example.com	web.example.com