参考文献:

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. Shell实现交互式登陆一台同时管理多台机器

    最近为了检测公司服务器的硬盘需要开10多台服务器的僚机来检测服务器,可是这10来台都是操作一样的命令,挨个操作下去太麻烦了 然后就想到了交互式登陆 这里需要创建一个Ip文件夹把你的Ip账户密码都放进去 ...

  2. loadrunner 场景设计-手工场景方案(Schedule)设计 Part 1

    参考:http://blog.sina.com.cn/s/articlelist_5314188213_1_1.html loadrunner 场景设计-手工场景方案(Schedule)设计 Part ...

  3. freebsd 隐藏ssh版本号

    方案一: vi /etc/ssh/sshd_config VersionAddendum 为空或者no或者别的信息 /etc/rc.d/sshd restart 方案二: https://kram.n ...

  4. centos7 忘记root密码,如何进入单用户模式。

    init方法 1.centos7的grub2界面会有两个入口,正常系统入口和救援模式: 2.修改grub2引导 在正常系统入口上按下"e",会进入edit模式,搜寻ro那一行,以l ...

  5. Pytorch笔记 (3) 科学计算2

    一.组织张量的元素 (1)重排张量元素 本节介绍在不改变 张量元素个数 和 各元素的值的情况下改变张量的大小 torch.Tensor类的成员方法 reshape() 参数是多个int类型的值. 如果 ...

  6. flask第一级

    #从flask这个包中导入Flask这个类 #Flask这个类是项目的核心,以后很多操作都是基于这个类的对象 #注册url.注册蓝图等都是基于这个类的对象 from flask import Flas ...

  7. 完全卸载oracle11g步骤(不可行,直接用oracle自用删除就行)

    完全卸载oracle11g步骤:1. 开始->设置->控制面板->管理工具->服务 停止所有Oracle服务.2. 开始->程序->oracle - OraHome ...

  8. python 并发编程 基于gevent模块 协程池 实现并发的套接字通信

    基于协程池 实现并发的套接字通信 客户端: from socket import * client = socket(AF_INET, SOCK_STREAM) client.connect(('12 ...

  9. windeployqt.exe 发布windows下qt产生的exe程序

    以官方 Qt 5.4.0+MinGW 开发环境为例,从开始菜单-->Qt 5.4.0-->5.4-->MinGW 4.9 (32-bit)-->Qt 5.4 for Deskt ...

  10. [转帖]Windows与Linux的命令行命令对比

    Windows与Linux的命令行命令对比 https://www.cnblogs.com/sztom/p/10785140.html * Windows不区分大小写,Linux区分大小写的. sn ...