文章目录
- 1、搭建一个网络yum源
- 2、基于域名访问的虚拟主机
- 3、基于端口来访问+域名
- 4、搭建个人网站
- 5、加密访问+显示自定义网页内容
1、搭建一个网络yum源
[root@test01 conf.d]
<virtualhost *:80>documentroot /var/www/html/ServerName 10.104.43.154alias /repo /var/www/html/repo
</virtualhost>
<directory /var/www/html/repo>require all grantedOptions Indexes FollowSymLinks
</directory>
<FilesMatch "\.(iso|img)$">Require all denied
</FilesMatch>
2、基于域名访问的虚拟主机
[root@test01 share]
./apache
├── a
└── b2 directories, 0 files[root@test01 apache]
[root@test01 apache]
[root@test01 conf.d]
<Virtualhost *:80>Documentroot /share/apache/aServerName www.a.com
</virtualhost>
<Directory /share/apache/a>require all granted
</Directory>
<Virtualhost *:80>Documentroot /share/apache/bServerName www.b.com
</virtualhost>
<Directory /share/apache/b>require all granted
</Directory>
[root@test01 /]
[root@test01 /]
success
[root@test01 share]
[root@test01 share]
restorecon reset /share/apache context unconfined_u:object_r:default_t:s0->system_u:object_r:default_t:s0
restorecon reset /share/apache/a context unconfined_u:object_r:default_t:s0->system_u:object_r:default_t:s0
restorecon reset /share/apache/a/index.html context unconfined_u:object_r:default_t:s0->system_u:object_r:default_t:s0
restorecon reset /share/apache/b context unconfined_u:object_r:default_t:s0->system_u:object_r:default_t:s0
restorecon reset /share/apache/b/index.html context unconfined_u:object_r:default_t:s0->system_u:object_r:default_t:s0
[root@test01 conf.d][root@test02 ~]
welcome a.com
[root@test02 ~]
welcome b.com
3、基于端口来访问+域名
[root@test01 conf.d]
Listen 8088
<Virtualhost *:8088>Documentroot /share/apache/aServerName www.a.com
</virtualhost>
<Directory /share/apache/a>require all granted
</Directory>
[root@test01 conf.d]
[root@test01 conf.d]
http_port_t tcp 8088, 80, 81, 443, 488, 8008, 8009, 8443, 9000
[root@test01 conf.d]
[root@test01 conf.d]
success
[root@test01 conf.d]
success
[root@test02 ~]
welcome a.com
[root@test02 ~]
welcome b.com
4、搭建个人网站
UserDir enabled
UserDir public_html
[root@test01 q7]
public_html/
└── index.html0 directories, 1 file
[root@test01 q7]
-rw-r--r--. root root unconfined_u:object_r:httpd_user_content_t:s0 index.html
[root@test01 q7]
[root@test01 q7]
drwx--x--x. 3 q7 q7 81 Sep 27 11:35 .
http://10.104.43.154/~q7/
5、加密访问+显示自定义网页内容
[root@test01 q7]
openssl genrsa > tlsweb.key
openssl req -new -key tlsweb.key > tlsweb.csr
openssl req -x509 -days 365 -in tlsweb.csr -key tlsweb.key > tlsweb.crt
[root@test01 tls]
/etc/pki/tls
cp /root/tlsweb.key ./private/
cp /root/tlsweb.crt certs/firewall-cmd --permanent --add-port=443/tcp
firewall-cmd --reload
[root@test01 conf.d]
<Virtualhost *:443>Documentroot /share/apache/aServerName www.a.comSSLEngine onSSLCertificateFile /etc/pki/tls/certs/tlsweb.crtSSLCertificateKeyFile /etc/pki/tls/private/tlsweb.key
</virtualhost>
<Directory /share/apache/a>require all granted
</Directory>[root@test01 conf.d]