服務器之httpd
1:安裝啟動
yum install -y httpd systemctl start httpd systemctl stop firewalld
2:發布頁面
默認發布目錄:/var/www/html/
默認發布文件:index.html
[[email protected] html]# vim index.html
~~~~~~
<h1> 測試頁面內容</h1>
~~~~~~
systemctl restart httpd
測試:http://172.25.254.120
3:修改默認發布文件
[[email protected] conf]# vim /etc/httpd/conf/httpd.conf
175 <IfModule dir_module> 176 DirectoryIndex index.html ##將index.html變成你想要更改的發布目錄 177 </IfModule>
4:更改默認發布目錄
[[email protected] conf]# vim /etc/httpd/conf/httpd.conf DocumentRoot "/zpy/html" ##要更改的發布目錄 <Directory "/zpy/html"> Require all granted ##允許所有人訪問 [[email protected]
測試:http://172.25.254.120
5:設置用戶的黑名單和白名單
[[email protected] 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)制作密碼
[[email protected] Desktop]# cd /etc/httpd/conf [[email protected] conf]# ls httpd.conf magic [[email protected] conf]# htpasswd -cm authfile admin ##註,此處-cm表示新建authfile文件,之前的文件內容將被覆蓋掉,所以如果要建立兩個或以上用戶時用-c New password: Re-type new password: Adding password for user admin [[email protected] conf]# cat authfile admin:$apr1$LQWb.7Yj$jSkQLKJwAn4JtRW9gnmHP
(2)添加密碼給測試頁
[[email protected] 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
測試:
在任意臺服務器上配置本地解析
[[email protected] 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