1、Apache安装与运行
一般情况下,系统已经安装好了。使用rpm -q httpd,如果没有安装,则使用yum -y install httpd安装。
运行:执行/usr/sbin/apachectl start即可。如果修改了配置文件记得使用/usr/sbin/apachectl restart重启apache服务。
2、虚拟主机配置
修改/etc/httpd/conf/http.conf文件:
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin dazhong159@163.com
DocumentRoot /home/cl/virtual_html
ServerNamewww.dazhong_destiny.com
DirectoryIndex index.html
</VirtualHost>
创建根目录:
mkdir /home/cl/virtual_html
改变目录访问权限:
chmod 711 /home/cl
chmod 711 /home/cl/virtual_html
在根目录下创建主页文件:
vi /home/cl/virtual_html/index.html
<h1>It's a good day today!</h1>
重启Apache服务:
/usr/sbin/apachectl restart
测试:
在虚拟机下打开FireFox浏览器,输入www.dazhong_destiny.com,可以看到正常浏览刚刚编辑的主页文件。
3、个人网站配置
修改/etc/httpd/conf/http.conf文件:
<IfModule mod_userdir.c>
UserDir disabled root
UserDir public_html
</IfModule>
<Directory /home/*/public_html>
AllowOverride FileInfo AuthConfig Limit
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
<Limit GET POST OPTIONS>
Order allow,deny
Allow from all
</Limit>
<LimitExcept GET POST OPTIONS>
Order deny,allow
Deny from all
</LimitExcept>
</Directory>
创建根目录:
mkdir /home/cl/public_html
改变目录访问权限:
chmod 711 /home/cl
chmod 711 /home/cl/public_html
在根目录下创建主页文件:
vi /home/cl/public_html/index.html
<h1>It's a good day today!</h1>
重启Apache服务:
/usr/sbin/apachectl restart
测试:
在虚拟机下打开FireFox浏览器,输入http://192.168.100.119/~cl,可以看到正常浏览刚刚编辑的主页文件。
4、个人网站认证和授权配置
在第三部基础上修改/etc/httpd/conf/http.conf文件,在<Directory /home/*/public_html>模块添加如下:
AuthType Basic
AuthName "mywebpwd"
AuthUserFile /var/www/passwd/mywebpwd
require valid-user
重启apache服务
/usr/sbin/apachectl restart
创建或者修改密码文件:
htppasswd -c /var/www/passwdmywebpwd cl //在/var/www/passwd目录下创建或修改密码文件,并且添加了一个用户cl。如下图:
测试:
在浏览器中输入http://192.168.100.119/~cl/,如下图,发现需要认证:
输入认真用户、密码之后,打开网页: