美文网首页
CentOS6安装使用httpd

CentOS6安装使用httpd

作者: 雷霆同学 | 来源:发表于2017-11-19 16:42 被阅读0次

    获取更多文章和更新,请关注我的个人主页:leiting6.cn

    1 安装httpd

    在终端输入命令httpd,如果提示命令没有找到,则说明没有安装httpd。使用:

    yum install -y httpd
    

    安装httpd,如果出现No package httpd available,可以尝试:

    yum --disableexcludes=all install -y httpd
    

    来安装httpd。如果出现其他错误,就利用搜索引擎看看有没有解决办法吧。

    2 修改配置文件

    首先:

    cd /etc/httpd
    ls
    

    可以看到,有这个目录有2个文件,一个README,一个welcome.conf

    README的内容简单看一下,主要来关注welcome.conf的内容:

    vi welcome.conf
    

    可以看到:

    #
    # This configuration file enables the default "Welcome"
    # page if there is no default index page present for
    # the root URL.  To disable the Welcome page, comment
    # out all the lines below.
    #
    <LocationMatch "^/+$">
        Options -Indexes
        ErrorDocument 403 /error/noindex.html
    </LocationMatch>
    

    很明白,意思是说,如果你没有配置httpd的话,默认显示Welcome页面;如果你不想使用Welcome页面,就讲下面所有行都注释掉。所以,直接使用vi编辑器把下面的都注释掉:

    #
    # This configuration file enables the default "Welcome"
    # page if there is no default index page present for
    # the root URL.  To disable the Welcome page, comment
    # out all the lines below.
    #
    #<LocationMatch "^/+$">
    #    Options -Indexes
    #    ErrorDocument 403 /error/noindex.html
    #</LocationMatch>
    

    然后:

    cd /etc/httpd/conf
    ls
    

    可以看到这个目录下有一个httpd.conf文件,这个就是httpd的配置文件,直接使用vi编辑器编辑它:

    vi httpd.conf
    

    我修改了如下几个地方:

    • listen 80修改为listen 2004(通过ip:2004端口来访问httpd页面)
    • DocumentRoot "/var/www/html"改成DocumentRoot "/www/wwwroot/leiting6.cn/tools" (访问httpd将显示该文件下的内容)
    • <Directory "/var/www/html"> ...改成<Directory "/www/wwwroot/leiting6.cn/tools"> (设置根目录一些权限)

    如果出现:

    httpd: Could not reliably determine the server's fully qualified domain name, using localhost.locald

    将httpd.conf中的:

    ServerName localhost:80改成ServerName localhost:2004

    最后,重启httpd服务:

    service httpd restart
    

    这样,访问我的域名:2004,就能打开访问tools文件夹下面的内容了。这只是httpd的一个最简单的应用,可以把一些常用文件放在tools文件夹下,方便查看和下载;更高级的应用,还是需要研究一下httpd.conf配置文件才行。

    相关文章

      网友评论

          本文标题:CentOS6安装使用httpd

          本文链接:https://www.haomeiwen.com/subject/txhpvxtx.html