首页 > 代码库 > 服务器之httpd
服务器之httpd
1:安装启动
yum install -y httpd systemctl start httpd systemctl stop firewalld
2:发布页面
默认发布目录:/var/www/html/
默认发布文件:index.html
[root@localhost html]# vim index.html
~~~~~~
<h1> 测试页面内容</h1>
~~~~~~
systemctl restart httpd
测试:http://172.25.254.120
3:修改默认发布文件
[root@locahlost conf]# vim /etc/httpd/conf/httpd.conf
175 <IfModule dir_module> 176 DirectoryIndex index.html ##将index.html变成你想要更改的发布目录 177 </IfModule>
4:更改默认发布目录
[root@locahlost conf]# vim /etc/httpd/conf/httpd.conf DocumentRoot "/zpy/html" ##要更改的发布目录 <Directory "/zpy/html"> Require all granted ##允许所有人访问 [root@locahlost conf]semanage fcontext -a -t httpd_sys_content_t ‘/zpy(/.*)?‘ ##更改发布目录的selinux安全上下文 [root@locahlost conf]restorecon -RvvF /zpy/ ##刷新 systemctl restart httpd.service
测试:http://172.25.254.120
5:设置用户的黑名单和白名单
[root@locahlost conf]# vim /etc/httpd/conf/httpd.conf
<Directory "/var/www/html"> Require all granted ##允许所有访问 Order Allow Deny ##此处的顺序和是否可以访问有关 Allow from http://172.25.254.120 Deny from ALL </Directory>
systemctl restart httpd
测试:在172.25.254.20上打开浏览器访问http://172.25.254.120 了可以看到测试页
但是其他ip地址打开的不能访问
6:对页面加密
(1)制作密码
[root@foundation120 Desktop]# cd /etc/httpd/conf [root@foundation120 conf]# ls httpd.conf magic [root@foundation120 conf]# htpasswd -cm authfile admin ##注,此处-cm表示新建authfile文件,之前的文件内容将被覆盖掉,所以如果要建立两个或以上用户时用-c New password: Re-type new password: Adding password for user admin [root@foundation20 conf]# cat authfile admin:$apr1$LQWb.7Yj$jSkQLKJwAn4JtRW9gnmHP
(2)添加密码给测试页
[root@locahlost conf]# vim /etc/httpd/conf/httpd.conf <Directory "/zpy/html"> # Require all granted AuthUserFile /etc/httpd/conf/authfile ##添加加密文件 AuthName "please into nameand passwd" ##显示标语 AuthType basic Require user admin ##允许admin用户登陆 # Require valid-user ##允许所有用户登陆 </Directory>
(3)测试
在测试时,当输入http://172.25.254.120时候会弹出登陆页面
7:在一台服务器上开启多个默任发布网页
前提:配置好默认发布
mkdir /var/www/zpy/news.zpy.com -p
mkdir /var/www/zpy/music.zpy.com -p
echo "news.zpy.com‘page" /var/www/zpy/news.zpy.com/index.html
echo "music.zpy.com‘page"/var/www/zpy/music.zpy.com/index.html
vim /etc/httpd/conf.d/default.conf
~~~~~~
<Virtualhost _default_:80> DocumentRoot "/var/www/html" CustomLog "logs/default.log" combined </Virtualhost>
~~~~~~
vim /etc/httpd/conf.d/news.conf
~~~~~~~
<Virtualhost *:80> ServerName news.zpy.com DocumentRoot /var/www/zpy/news.zpy.com CustomLog "logs/news.log" combined </Virtualhost> <Directory "/var/www/zpy/news.zpy.com"> Require all granted </Directory>
~~~~~~~
vim /etc/httpd/conf.d/music.conf
~~~~~~
<Virtualhost *:80> ServerName music.zpy.com DocumentRoot /var/www/zpy/music.zpy.com CustomLog "logs/music.log" combined </Virtualhost> <Directory "/var/www/zpy/music.zpy.com"> Require all granted </Directory>
~~~~~~
systemctl restart httpd
测试:
在任意台服务器上配置本地解析
[root@foundation20 Desktop]# cat /etc/hosts
172.25.254.120 www.zpy.com music.zpy.com news.zpy.com
访问 www.zpy.com 出现默认发布页面
访问 music.zpy.com 出现news.zpy.com‘page发布页面
访问 news.zpy.com 出现news.zpy.com‘page发布页面
本文出自 “12462896” 博客,请务必保留此出处http://12472896.blog.51cto.com/12462896/1955748
服务器之httpd