zoukankan      html  css  js  c++  java
  • Httpd服务入门知识-Httpd服务常见配置案例之定义站点主页面及错误页面配置

          Httpd服务入门知识-Httpd服务常见配置案例之定义站点主页面及错误页面配置

                                                    作者:尹正杰

    版权声明:原创作品,谢绝转载!否则将追究法律责任。

    一.定义站点主页面

    [root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf/httpd.conf  | grep DirectoryIndex
        DirectoryIndex index.html
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# ll /data/www/html/
    total 8
    -rw-r--r-- 1 root root 15 Dec  7 20:07 index.html
    -rw-r--r-- 1 root root 31 Dec  7 20:22 info.html
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# cat /data/www/html/index.html 
    /data/www/html
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# cat /data/www/html/info.html 
    <h1>尹正杰到此一游</h1>
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# vim /etc/httpd/conf/httpd.conf
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf/httpd.conf  | grep DirectoryIndex
        DirectoryIndex info.html
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# httpd -t
    Syntax OK
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# systemctl restart httpd.service 
    [root@node101.yinzhengjie.org.cn ~]#

    二.错误页面配置

    1>.删除站点主页文件

    [root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf/httpd.conf  | grep DocumentRoot
    DocumentRoot "/data/www/html"
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf/httpd.conf  | grep DirectoryIndex
        DirectoryIndex info.html
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# rm -f /data/www/html/info.html 
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# ll /data/www/html/
    total 4
    -rw-r--r-- 1 root root 15 Dec  7 20:07 index.html
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# 

    2>.查看"/etc/httd/conf.d"目录下的"welcome.conf"配置文件

    [root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf/httpd.conf  | grep ServerRoot
    ServerRoot "/etc/httpd"
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf/httpd.conf  | grep IncludeOptional
    IncludeOptional conf.d/*.conf
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# ll /etc/httpd/conf.d/              #从主配置文件中可以看到启动httpd服务时会加载该目录下的文件哟~
    total 20
    -rw-r--r-- 1 root root 2926 Aug  8 19:41 autoindex.conf
    -rw-r--r-- 1 root root   66 Dec  7 20:15 document_root.conf
    -rw-r--r-- 1 root root  366 Aug  8 19:42 README
    -rw-r--r-- 1 root root 1252 Aug  6 21:44 userdir.conf
    -rw-r--r-- 1 root root  824 Aug  6 21:44 welcome.conf
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# cat /etc/httpd/conf.d/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. 
    #
    # NOTE: if this file is removed, it will be restored on upgrades.
    #
    <LocationMatch "^/+$">
        Options -Indexes
        ErrorDocument 403 /.noindex.html                  #不难发现,如果有403的错误,就会使用"/.noindex.html"的别名文件来替换错误网页
    </LocationMatch>
    
    <Directory /usr/share/httpd/noindex>
        AllowOverride None
        Require all granted
    </Directory>
    
    Alias /.noindex.html /usr/share/httpd/noindex/index.html      #我们看到"/.noindex.html"的别名真正存放路径为"/usr/share/httpd/noindex/index.html"
    Alias /noindex/css/bootstrap.min.css /usr/share/httpd/noindex/css/bootstrap.min.css
    Alias /noindex/css/open-sans.css /usr/share/httpd/noindex/css/open-sans.css
    Alias /images/apache_pb.gif /usr/share/httpd/noindex/images/apache_pb.gif
    Alias /images/poweredby.png /usr/share/httpd/noindex/images/poweredby.png
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# 

    3>.经过上一步骤的分析,我们将"/etc/httpd/conf.d/welcome.conf"配置文件改成不以".conf"结尾的文件名

    [root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf/httpd.conf  | grep ServerRoot
    ServerRoot "/etc/httpd"
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf/httpd.conf  | grep IncludeOptional
    IncludeOptional conf.d/*.conf
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# ll /etc/httpd/conf.d/
    total 20
    -rw-r--r-- 1 root root 2926 Aug  8 19:41 autoindex.conf
    -rw-r--r-- 1 root root   66 Dec  7 20:15 document_root.conf
    -rw-r--r-- 1 root root  366 Aug  8 19:42 README
    -rw-r--r-- 1 root root 1252 Aug  6 21:44 userdir.conf
    -rw-r--r-- 1 root root  824 Aug  6 21:44 welcome.conf
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# mv /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.d/welcome.conf-`date +%F`       #我们暂时修改文件名的后缀
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# ll /etc/httpd/conf.d/
    total 20
    -rw-r--r-- 1 root root 2926 Aug  8 19:41 autoindex.conf
    -rw-r--r-- 1 root root   66 Dec  7 20:15 document_root.conf
    -rw-r--r-- 1 root root  366 Aug  8 19:42 README
    -rw-r--r-- 1 root root 1252 Aug  6 21:44 userdir.conf
    -rw-r--r-- 1 root root  824 Aug  6 21:44 welcome.conf-2019-12-07
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# 

    4>.重启httpd服务,观察页面出现了如下图所示的界面

    [root@node101.yinzhengjie.org.cn ~]# systemctl restart httpd
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# ss -ntl
    State      Recv-Q Send-Q                                         Local Address:Port                                                        Peer Address:Port              
    LISTEN     0      128                                                        *:80                                                                     *:*                  
    LISTEN     0      128                                                        *:22                                                                     *:*                  
    LISTEN     0      128                                                       :::22                                                                    :::*                  
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# systemctl status httpd
    ● httpd.service - The Apache HTTP Server
       Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
       Active: active (running) since Sat 2019-12-07 20:50:39 CST; 11s ago
         Docs: man:httpd(8)
               man:apachectl(8)
      Process: 7415 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
      Process: 5886 ExecReload=/usr/sbin/httpd $OPTIONS -k graceful (code=exited, status=0/SUCCESS)
     Main PID: 7420 (httpd)
       Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
       CGroup: /system.slice/httpd.service
               ├─7420 /usr/sbin/httpd -DFOREGROUND
               ├─7421 /usr/sbin/httpd -DFOREGROUND
               ├─7422 /usr/sbin/httpd -DFOREGROUND
               ├─7423 /usr/sbin/httpd -DFOREGROUND
               └─7424 /usr/sbin/httpd -DFOREGROUND
    
    Dec 07 20:50:39 node101.yinzhengjie.org.cn systemd[1]: Starting The Apache HTTP Server...
    Dec 07 20:50:39 node101.yinzhengjie.org.cn systemd[1]: Started The Apache HTTP Server.
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# 

    5>.总结

        根据上面的操作,如果出现错误的403网页,咱们也可以自定义自己的错误页面哟~
  • 相关阅读:
    pat 乙级1084 外观数列
    将int 转换为string 函数 to_string()
    stl find_first_not_of()函数
    小写转变为大写函数toupper()
    基础实验2-2.3 组合数的和 (15分)
    基础实验2-2.2 求集合数据的均方差 (15分)
    习题1.9 有序数组的插入 (20分)
    用eclipse运行算法第四版的BinarySearch
    关于脱发
    HUD-2586(LCA板子)
  • 原文地址:https://www.cnblogs.com/yinzhengjie/p/12003078.html
Copyright © 2011-2022 走看看