参考文献:

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. 转载 Golang []byte与string转换的一个误区

    Golang []byte与string转换的一个误区 https://www.oyohyee.com/post/Note/golang_byte_to_string/ 2019-08-10 23:4 ...

  2. 【转载】解决jquery-1.10.2.min.map 404 Not Found错误

    最近写代码遇到问题,报错说jquery-1.10.2.min.map NOT FOUND.但是我检查了几遍代码发现代码中没有问题,而且根本就没有包含甚至提到jquert-1.10.2.min.map这 ...

  3. Java学习之==>注解

    一.概述 关于注解,首先引入官方文档的一句话:Java 注解用于为 Java 代码提供元数据.作为元数据,注解不直接影响你的代码执行,但也有一些类型的注解实际上可以用于这一目的.接下我将从注解的定义. ...

  4. JS实战篇

    实现选项卡的选择: 效果图如下: 代码如下: <!DOCTYPE html> <html> <head> <meta charset="UTF-8& ...

  5. Python+requests+excel接口测试

    2018-06-14   17:00:13 环境准备: - Python 3.7 - requests库 - xlrd 1.创建Excel文件 2.读取Excel文件 import xlrd clas ...

  6. Shell编程、part1

    1.shell简介 2. shell分类 3. 查看shell 4. 第一个shell脚本 5. shell编程常用命令 5.1 grep 5.2 cut 5.3 sort 5.4 uniq 5.5 ...

  7. 磁盘的分区和挂载(mount)

    一.挂载问题的引入 我们大多数人用惯了windos系统,对linux系统中磁盘的管理就先入为主,不太好理解挂载这一动作.在linux系统中添加一块新磁盘后,要进行分区.格式化(分配文件系统).挂载.当 ...

  8. python每日一练:0002题

    第 0002 题:将 0001 题生成的 200 个激活码(或者优惠券)保存到 MySQL 关系型数据库中. 示例代码: import os import string import random i ...

  9. vue-蒙层弹窗里的内容滚动。外层大页面禁止滚动

      此需求 有两种方法,第一种,这种方法适用于,底层 和弹窗是两个平行的没有关系的两部分.重叠(https://blog.csdn.net/yuhk231/article/details/741717 ...

  10. DataGridView中EnditCommit()调用之后,单元格的内容被全选了,每次输入都要鼠标点击定位到最后才能继续输入

    因为某些需求,DataGridView在输入一次内容,就要调用ECommitEdit(DataGridViewDataErrorContexts.Commit)来将内容提交,但是这样做之后,控件就会当 ...