Web服务器搭建

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/,如下图,发现需要认证:

       

        输入认真用户、密码之后,打开网页:

       

       

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值