標簽:網絡服務 linux 配置文件 web服務器 http
Linux網絡服務之HTTP(1)
實驗要求:
1、主機名設爲:www.zhy.com,默认首頁包括:index.html、index.php,開啓保持連接,確認默認httpd是否支持php
2、只允許192.168.1.1訪問www.zhy.com,允许所有用户訪問www.zhy.com/user/index.html
3、客户端訪問/var/www/html/admin/需要輸入用戶名密碼驗證
4、客户端訪問http://www.zhy.com/bbs时可以訪問/var/www/html/user/bbs下的網頁
實驗步驟:
1、安裝軟件包
搭建http服务需要安裝軟件包httpd
[root@localhost ~]# yum -y install httpd
[root@localhost ~]# vim /var/www/html/index.html //准备訪問界面
前提需配置DNS爲網站做域名解析
2、修改配置文件
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf //修改http服務主配置文件
……
74 KeepAlive On //開啓保持連接功能
……
265 ServerName www.zhy.com //設置域名
……
281 DocumentRoot "/var/www/html" //網站默認根目錄
……
306 <Directory "/var/www/html">
……
332 Order allow,deny
333 # Allow from all //默认允许所有人訪問,此处注释掉
334 Allow from 192.168.1.1 //只允許該IP地址訪問
……
</Directory>
336 <Directory "/var/www/html/user"> //设置对该目录的訪問控制
337 Order allow,deny
338 Allow from all //允许所有人訪問
339 </Directory>
340 <Directory "/var/www/html/admin">
341 Order allow,deny //先允許,後拒絕,默認拒絕所有
342 Allow from all
343 AuthName "Please Input Password" //彈窗提示
344 AuthType Basic //認證類型
345 AuthUserFile "/etc/httpd/.vuser" //認證文件
346 Require valid-user //指定授權用戶或組
347 </Directory>
348 Alias /bbs/ "/var/www/html/bbs" //設置別名
……
391 DirectoryIndex index.html index.php //默認主頁文件
……
[root@localhost ~]# htpasswd -c /etc/httpd/.vuser admin //創建認證用戶
New password: //創建密碼
Re-type new password:
Adding password for user admin
3、啓動服務,設置服務開機自動啓動
[root@localhost ~]# service httpd restart
停止 httpd: [確定]
啓動 httpd: [確定]
[root@localhost ~]# chkconfig httpd on
4、測試
本文出自 “煙頭網管” 博客,请务必保留此出处http://8838848.blog.51cto.com/8828848/1405673
Linux網絡服務之HTTP(1),布布扣,bubuko.com
標簽:網絡服務 linux 配置文件 web服務器 http
原文地址:http://8838848.blog.51cto.com/8828848/1405673