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

                                                作者:尹正杰

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

一.定义站点主页面

  1. [root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf/httpd.conf | grep DirectoryIndex
  2. DirectoryIndex index.html
  3. [root@node101.yinzhengjie.org.cn ~]#
  4. [root@node101.yinzhengjie.org.cn ~]# ll /data/www/html/
  5. total
  6. -rw-r--r-- root root Dec : index.html
  7. -rw-r--r-- root root Dec : info.html
  8. [root@node101.yinzhengjie.org.cn ~]#
  9. [root@node101.yinzhengjie.org.cn ~]# cat /data/www/html/index.html
  10. /data/www/html
  11. [root@node101.yinzhengjie.org.cn ~]#
  12. [root@node101.yinzhengjie.org.cn ~]# cat /data/www/html/info.html
  13. <h1>尹正杰到此一游</h1>
  14. [root@node101.yinzhengjie.org.cn ~]#
  15. [root@node101.yinzhengjie.org.cn ~]# vim /etc/httpd/conf/httpd.conf
  16. [root@node101.yinzhengjie.org.cn ~]#
  17. [root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf/httpd.conf | grep DirectoryIndex
  18. DirectoryIndex info.html
  19. [root@node101.yinzhengjie.org.cn ~]#
  20. [root@node101.yinzhengjie.org.cn ~]# httpd -t
  21. Syntax OK
  22. [root@node101.yinzhengjie.org.cn ~]#
  23. [root@node101.yinzhengjie.org.cn ~]# systemctl restart httpd.service
  24. [root@node101.yinzhengjie.org.cn ~]#

二.错误页面配置

1>.删除站点主页文件

  1. [root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf/httpd.conf | grep DocumentRoot
  2. DocumentRoot "/data/www/html"
  3. [root@node101.yinzhengjie.org.cn ~]#
  4. [root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf/httpd.conf | grep DirectoryIndex
  5. DirectoryIndex info.html
  6. [root@node101.yinzhengjie.org.cn ~]#
  7. [root@node101.yinzhengjie.org.cn ~]# rm -f /data/www/html/info.html
  8. [root@node101.yinzhengjie.org.cn ~]#
  9. [root@node101.yinzhengjie.org.cn ~]# ll /data/www/html/
  10. total
  11. -rw-r--r-- root root Dec : index.html
  12. [root@node101.yinzhengjie.org.cn ~]#
  13. [root@node101.yinzhengjie.org.cn ~]#

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

  1. [root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf/httpd.conf | grep ServerRoot
  2. ServerRoot "/etc/httpd"
  3. [root@node101.yinzhengjie.org.cn ~]#
  4. [root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf/httpd.conf | grep IncludeOptional
  5. IncludeOptional conf.d/*.conf
  6. [root@node101.yinzhengjie.org.cn ~]#
  7. [root@node101.yinzhengjie.org.cn ~]# ll /etc/httpd/conf.d/              #从主配置文件中可以看到启动httpd服务时会加载该目录下的文件哟~
  8. total 20
  9. -rw-r--r-- 1 root root 2926 Aug 8 19:41 autoindex.conf
  10. -rw-r--r-- 1 root root 66 Dec 7 20:15 document_root.conf
  11. -rw-r--r-- 1 root root 366 Aug 8 19:42 README
  12. -rw-r--r-- 1 root root 1252 Aug 6 21:44 userdir.conf
  13. -rw-r--r-- 1 root root 824 Aug 6 21:44 welcome.conf
  14. [root@node101.yinzhengjie.org.cn ~]#
  15. [root@node101.yinzhengjie.org.cn ~]# cat /etc/httpd/conf.d/welcome.conf
  16. #
  17. # This configuration file enables the default "Welcome" page if there
  18. # is no default index page present for the root URL. To disable the
  19. # Welcome page, comment out all the lines below.
  20. #
  21. # NOTE: if this file is removed, it will be restored on upgrades.
  22. #
  23. <LocationMatch "^/+$">
  24. Options -Indexes
  25. ErrorDocument 403 /.noindex.html                  #不难发现,如果有403的错误,就会使用"/.noindex.html"的别名文件来替换错误网页
  26. </LocationMatch>
  27.  
  28. <Directory /usr/share/httpd/noindex>
  29. AllowOverride None
  30. Require all granted
  31. </Directory>
  32.  
  33. Alias /.noindex.html /usr/share/httpd/noindex/index.html      #我们看到"/.noindex.html"的别名真正存放路径为"/usr/share/httpd/noindex/index.html"
  34. Alias /noindex/css/bootstrap.min.css /usr/share/httpd/noindex/css/bootstrap.min.css
  35. Alias /noindex/css/open-sans.css /usr/share/httpd/noindex/css/open-sans.css
  36. Alias /images/apache_pb.gif /usr/share/httpd/noindex/images/apache_pb.gif
  37. Alias /images/poweredby.png /usr/share/httpd/noindex/images/poweredby.png
  38. [root@node101.yinzhengjie.org.cn ~]#
  39. [root@node101.yinzhengjie.org.cn ~]#

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

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

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

  1. [root@node101.yinzhengjie.org.cn ~]# systemctl restart httpd
  2. [root@node101.yinzhengjie.org.cn ~]#
  3. [root@node101.yinzhengjie.org.cn ~]# ss -ntl
  4. State Recv-Q Send-Q Local Address:Port Peer Address:Port
  5. LISTEN *: *:*
  6. LISTEN *: *:*
  7. LISTEN ::: :::*
  8. [root@node101.yinzhengjie.org.cn ~]#
  9. [root@node101.yinzhengjie.org.cn ~]# systemctl status httpd
  10. httpd.service - The Apache HTTP Server
  11. Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
  12. Active: active (running) since Sat -- :: CST; 11s ago
  13. Docs: man:httpd()
  14. man:apachectl()
  15. Process: ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=/SUCCESS)
  16. Process: ExecReload=/usr/sbin/httpd $OPTIONS -k graceful (code=exited, status=/SUCCESS)
  17. Main PID: (httpd)
  18. Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
  19. CGroup: /system.slice/httpd.service
  20. ├─ /usr/sbin/httpd -DFOREGROUND
  21. ├─ /usr/sbin/httpd -DFOREGROUND
  22. ├─ /usr/sbin/httpd -DFOREGROUND
  23. ├─ /usr/sbin/httpd -DFOREGROUND
  24. └─ /usr/sbin/httpd -DFOREGROUND
  25.  
  26. Dec :: node101.yinzhengjie.org.cn systemd[]: Starting The Apache HTTP Server...
  27. Dec :: node101.yinzhengjie.org.cn systemd[]: Started The Apache HTTP Server.
  28. [root@node101.yinzhengjie.org.cn ~]#
  29. [root@node101.yinzhengjie.org.cn ~]#

5>.总结

  1. 根据上面的操作,如果出现错误的403网页,咱们也可以自定义自己的错误页面哟~

Httpd服务入门知识-Httpd服务常见配置案例之定义站点主页面及错误页面配置的更多相关文章

  1. Httpd服务入门知识-Httpd服务常见配置案例之虚拟主机

    Httpd服务入门知识-Httpd服务常见配置案例之虚拟主机 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.虚拟主机实现方案 1>.Apache httpd 有三种实现虚 ...

  2. Httpd服务入门知识-Httpd服务常见配置案例之Apache的工作做状态status页面

    Httpd服务入门知识-Httpd服务常见配置案例之Apache的工作做状态status页面 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.status功能概述 status页 ...

  3. Httpd服务入门知识-Httpd服务常见配置案例之ServerSignature指令选项

    Httpd服务入门知识-Httpd服务常见配置案例之ServerSignature指令选项 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.ServerSignature指令概述 ...

  4. Httpd服务入门知识-Httpd服务常见配置案例之实现用户家目录的http共享

    Httpd服务入门知识-Httpd服务常见配置案例之实现用户家目录的http共享 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.实现用户家目录的http共享前提 在配置家目录共 ...

  5. Httpd服务入门知识-Httpd服务常见配置案例之定义路径别名

    Httpd服务入门知识-Httpd服务常见配置案例之定义路径别名 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任.   一.创建测试数据 [root@node101.yinzhengj ...

  6. Httpd服务入门知识-Httpd服务常见配置案例之设定默认字符集

    Httpd服务入门知识-Httpd服务常见配置案例之设定默认字符集 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.查看生产环境中使用的字符集案例 1>.查看腾讯设置的默认 ...

  7. Httpd服务入门知识-Httpd服务常见配置案例之日志设定

    Httpd服务入门知识-Httpd服务常见配置案例之日志设定 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.日志类型 [root@node101.yinzhengjie.org ...

  8. Httpd服务入门知识-Httpd服务常见配置案例之基于客户端来源地址实现访问控制

    Httpd服务入门知识-Httpd服务常见配置案例之基于客户端来源地址实现访问控制 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Options  1>.OPTIONS指 ...

  9. Httpd服务入门知识-Httpd服务常见配置案例之基于用户账号实现访问控制

    Httpd服务入门知识-Httpd服务常见配置案例之基于用户账号实现访问控制 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.基于用户的访问控制概述 认证质询: WWW-Auth ...

随机推荐

  1. The import junit cannot be resolved解决问题

    第一次安装Junit,配置环境之后发现添加语句import junit.framework.TestCase; 编译错误 解决:项目右键Properties->Java Build Path-& ...

  2. 基于web公交查询系统自我安排进度

    这周完成站点信息管理

  3. C# PKCS7加密解密

    //加密字符串 public string Encryption(string toE) { //加密和解密必须采用相同的key,具体自己填写,但是必须为32位 "); RijndaelMa ...

  4. eclipse.ini相关问题

    一般新装的eclipse,在eclipse.ini文件中,有设置默认的内存信息,如果你要开发一个大的项目或者导入大的项目,那么,eclipse就会时不时报出这样的错误:An internal erro ...

  5. 【layui】日期选择一闪而过问题

    添加 trigger: 'click',

  6. 仿微信、qq聊天,@好友功能

    文章主要介绍我们平时用的qq,微信输入框里面的@功能 如图,输入@符号 会出现一个ul ul的位置随着@符号的位置变动 下面是代码 希望对大家有用 直接全部复制,在编辑器中打开 即可 <!DOC ...

  7. 1082 射击比赛 PAT (Basic Level)

    题目链接: https://pintia.cn/problem-sets/994805260223102976/problems/994805260990660608 分析: 这是典型的给出编号和得分 ...

  8. C#子线程执行完后,调用主线程的方法

    private delegate void CheckVersionNumber_CallBack(string str);//定义一个为委托 用于 检测版本 //检测版本private void m ...

  9. python环境安装及其就业状况

    一,下载及安装 1.进入官网下载 2.安装 二,就业前景 1.Python就业行情和前景分析之一 岗位数量 2..Python就业行情和前景分析之一 学历要求 3.工资状况

  10. Unable to connect to HBase using Phoenix JDBC Driver

    Feb 01, 2017; 5:21pm Unable to connect to HBase using Phoenix JDBC Driver 9 posts Hi All,   I am try ...