参考文献:

https://www.cnblogs.com/snake553/p/8856729.html

https://blog.csdn.net/yejinxiong001/article/details/77527189


步骤:

1、安装Apache,也就是httpd服务

[root@localhost html]# yum install httpd

2、配置

  配置httpd.conf。

  首先配置Listen。这个配置项是Apache的监听位置,Apache默认监听80端口,将配置项更改为localhost的IP只监听来自本地主机的连接。

Listen 127.0.0.1:80

  或者使用外网IP监听来自远程主机的连接。

  配置DocumentRoot

  这个配置项是网站默认目录的位置,默认位置是/var/www/html,如下

DocumentRoot "/var/www/html"

  如果需要更改可以将引号中的路径更换。

3、80端口

  因为Apache占用80端口,所以要确保80端口畅通。

  查看80端口是否开启:

firewall-cmd --query-port=80/tcp

  返回的是yes说明已经开启,返回no则是没有开启。

  开启80端口:

firewall-cmd --add-port=80/tcp --permanent   # --permanent 永久生效,没有此参数重启后失效

  关闭80端口:

firewall-cmd --remove-port=80/tcp --permanent   # --permanent 永久生效,没有此参数重启后失效

  重启防火墙:

firewall-cmd --reload

4、index.html

  index.html是使用域名访问时的默认页面,在/var/www/html下创建index.html

touch /var/www/html/index.html

  然后编辑一下,输入一下hello world

5、启动Apache

systemctl start httpd.service

  检查Apache运行状态:

systemctl status httpd

  Apache启动后就可以在浏览器中输入 localhost 进行访问,显示的内容和/var/www/html/index.html的内容是一致的。

6、开启目录结构

在查询资料的时候发现文件列表是由mod_autoindex.so模块控制的,按照教程中在/etc/httpd/conf/httpd.conf配置文件中找不到这个模块

但是在配置文件中看到如下代码:

……

# Example:
# LoadModule foo_module modules/mod_foo.so
Include conf.modules.d/*.conf
……

  大概的意思就是装载的模块包含在conf.modules.d目录下后缀名为.conf的文件中

  于是就把conf.modules.d下的所有.conf文件都查看了一遍

  在/etc/httpd/conf.modules.d/00-base.conf中找到了mod_autoindex.so模块

LoadModule autoindex_module modules/mod_autoindex.so

  这个模块是默认已经装载的,其实完全没有必要找到模块具体位置。

  配置welcome.conf

  welcome.conf位置在/etc/httpd/conf.d/下

[root@localhost html]# vim /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
</LocationMatch> <Directory /usr/share/httpd/noindex>
AllowOverride None
Require all granted
</Directory> Alias /.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

  将Options -Indexes中的‘-’改为‘+’即可,更改后是上面的样子。

  然后重启一下httpd服务

systemctl restart httpd

  文件目录列表就成功开启了

  但是这时候需要回过头来将前面创建的index.html删除掉,不然在使用域名访问时会默认访问index.html,或者将index.html创建为目录,在目录里上传文件。

基于Apache服务在centos7上搭建文件列表的更多相关文章

  1. 基于Hexo且在GitHub上搭建博客

    title: 基于Hexo且在GitHub上搭建博客 Welcome to Fofade's Blog! 搭建初衷 大大小小,大学两年,玩了很多,也学了很多. 回首望之,曾经不知道的,现在是知道了,但 ...

  2. centos7上搭建开源系统jforum

    centos7上搭建好tomcat,mysql; 将 jforum-2.6.2.war放到tomcat目录的webapps下: 启动tomcat,./startup.sh ,查看webapp下jfor ...

  3. [深度学习] centos7上搭建基于Anaconda3的caffe+pycaffe环境(python3.6)

    本文记录从零开始在CentOS7.x系统上搭建Caffe深度学习平台,并配置pycaffe环境.(由于在虚拟机上搭建,所以为CPU_ONLY模式) 1.选择CentOS7 mini版镜像安装虚拟机 镜 ...

  4. centos7上搭建http服务器以及设置目录访问

    参考文献:http://www.jb51.net/article/137596.htm,原文摘抄如下,并根据具体需要作了相应的修改. 步骤: 1. 安装httpd服务 sudo yum install ...

  5. Tomcat:基于Apache+Tomcat的集群搭建

    根据Tomcat的官方文档说明可以知道,使用Tomcat配置集群需要与其它Web Server配合使用才可以完成,典型的有Apache和IIS. 这里就使用Apache+Tomcat方式来完成基于To ...

  6. centos7 上搭建私有云

    OwnCloud环境搭建 一. 环境搭建 1. 环境需求 服务器操作系统:Centos7.0 外网服务器操作系统:Centos7.0 Php版本号:5.4.16 Mysql版本号:5.5.52 Apa ...

  7. 02.centos7上搭建hadoop集群

    接上一篇  https://www.cnblogs.com/yjm0330/p/10069224.html 一.准备工作:无密登陆 1.编辑/etc/hosts文件,分别增加 192.168.2.24 ...

  8. Centos7上搭建redis主从

    1. 节点(服务器)数量说明 按照redis官方建议:salve和master的数量按照2n+1台服务器(1台master节点,2n台slave节点) 有兴趣的可以了解下redis的master选举机 ...

  9. Centos7上搭建ftp服务器

    ftp服务器搭建 1.安装好centos系统,配好yum仓库 其中vsftpd源在这下载 http://rpmfind.net/linux/rpm2html/search.php?query=vsft ...

随机推荐

  1. ubuntu下mysql数据库存储路径修改

    一.安装mysql ubuntu系统安装配置APT源,apt install mysql-server mysql-client 二.查看安装端口情况 sudo netstat -tap | grep ...

  2. Firefox63以后 禁止自动更新方式

    参考:https://bbs.kafan.cn/thread-2135160-1-1.html 63版以后在prefs.js文件末尾加代码来禁止自动更新的方式失效 新方式: 使用DisableAppU ...

  3. PLSQL查看表创建语句

    在我们想要查看的表上右键选择view:

  4. sigmoid function的直观解释

    Sigmoid function也叫Logistic function, 在logistic regression中扮演将回归估计值h(x)从 [-inf, inf]映射到[0,1]的角色. 公式为: ...

  5. Web05_jQuery

    在官方网站下载包,下载不带有min的包 http://jquery.com/download/ 案例一:使用JQ完成首页定时弹出广告图片 01_JQ入门 01_jQuery入门.html <!D ...

  6. 本地虚拟机部署线上php程序---不需要修改数据库信息

    1.特别注意:拿来线上php程序后一般是不需要修改config.php里面的数据库连接信息的,如果修改了会报错:站点已关闭.所以 2.5 步骤是需要省略的.如果拿来的是最开始的php源码,需要配置原始 ...

  7. 在Spring容器外调用bean

    这个东西源于这种需求:一个应用丢到服务其后,不管用户有没有访问项目,这个后台线程都必须给我跑,而且这个线程还调用了Spring注入的bean,这样自然就会想到去监听Servlet的状态,当Servle ...

  8. Golang基础(7):go的net/rpc用法

    一:PRC是什么? RPC(Remote Procedure Call) 远程过程调用,是一个计算通信协议.该协议允许一台计算机上的程序调用另外一台计算机上的程序.远程过程调用就是2个不在同一台计算机 ...

  9. python学习之模块-模块(五)

    5.10 包 5.10.1 包的概念 [官网解释] Packages are a way of structuring Python's module namespace by using " ...

  10. 用番茄工作法提升工作效率 (四)ToDoList的持续优化

    一.写在前面 前面三篇文章,系统介绍了我如何使用番茄工作法,并结合“自制”的桌面ToDoList工具来实现自己的任务管理. 自制ToDoList的初衷是自我管理,但是好友看到我的桌面(程序)后,建议我 ...