1, 安装
[root@D-WY-DEV8 ~]# yum install httpd # 安装 httpd
[root@D-WY-DEV8 ~]# systemctl start httpd # 启动 httpd
[root@D-WY-DEV8 ~]# systemctl enable httpd # 开机自启动 httpd
[root@D-WY-DEV8 ~]# httpd -v # 打印版本
Server version: Apache/2.4.6 (CentOS)
Server built: Apr 2 2020 13:13:23
2, 配置
[root@D-WY-DEV8 ~]# vim /etc/httpd/conf/httpd.conf # 编辑
[root@D-WY-DEV8 ~]# cat /etc/httpd/conf/httpd.conf # 将网站根目录指向服务器的数据分区
DocumentRoot "/mnt/nokia/htdocs"
<Directory "/mnt/nokia">
AllowOverride None
Require all denied
</Directory>
<Directory "/mnt/nokia/htdocs">
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<Directory "/mnt/nokia/htdocs/release">
AllowOverride None
Require all granted
Options +Indexes +FollowSymLinks
IndexOptions FancyIndexing HTMLTable
IndexOptions NameWidth=*
IndexOptions Charset=UTF-8
HeaderName /release-desc/header.html
</Directory>
[root@D-WY-DEV8 ~]# systemctl restart httpd
- AllowOverride: 就是指明Apache服务器是否去找 .htacess 文件作为配置文件,如果设置为none,那么服务器将忽略。
- Indexes: 在该目录没有index.html文件时,就呈现目录下的所有文件和子目录。
- FollowSymLinks: 服务器允许在此目录中使用符号连接。
- FancyIndexing:好象是一种目录索引的方法,如果不配置此项,文件列表,就没有更新时间、大小之类的详细信息。
- HTMLTable: 配置此项,好象会自动配置 FancyIndexing, 提供了一种目录浏览的呈现方式。
- NameWidth=*: 不限制文件名的长度,在目录浏览列表,呈现完整的长文件名或目录名。
- Charset=UTF-8: 设置本页面响应头的编码,整站最好都用 utf-8 编码。
- HeaderName:指明了本目录浏览页面的上部,呈现什么内容。
- AllowOverride, 更详细的使用方法见: http://httpd.apache.org/docs/2.4/mod/core.html#directory
- Options,更详细的使用方法,参见:https://cwiki.apache.org/confluence/display/HTTPD/DirectoryListings
- IndexOptions,更详细使用方法,参见:http://httpd.apache.org/docs/trunk/mod/mod_autoindex.html#indexoptions
- HeaderName,更详细的使用方法,参见:http://httpd.apache.org/docs/trunk/mod/mod_autoindex.html#headername
3,准备目录结构及文件
[root@D-WY-DEV8 ~]# tree /mnt/nokia/htdocs
/mnt/nokia/htdocs
├── release
│ ├── do-file-generator-1.0.0.tar.gz
│ ├── do-layer-import-1.0.0.tar.gz
│ ├── do-param-updater-1.0.0.tar.gz
│ ├── do-qiu-monitor-1.0.0.tar.gz
│ └── do-user-reporter-1.0.0.tar.gz
└── release-desc
└── header.html
[root@D-WY-DEV8 ~]# cat /mnt/nokia/htdocs/release-desc/header.html
<H1>Index of /release</H1>
<H2>do-shunc 项目软件分发</H2>
<P>这里备份了 do-shunc 项目下,每一个在线上部署的子模块的所有版本。</P>
4, 页面呈现效果
5, 其他问题
如果访问 http://10.161.97.190/release 时,报 403 错误,
# 确认 selinux 是开启的
[root@D-WY-DEV8 etc]# getenforce
Enforcing
# 临时关一下 selinux,如果能打开页面,确认是 selinux 的锅,再继续往下走,否则就看操作系统目录权限的设置
[root@D-WY-DEV8 etc]# setenforce 1
# 查看文件属性
[root@D-WY-DEV8 ~]# ls -Z /mnt/nokia/htdocs
drwxr-xr-x. root root unconfined_u:object_r:unlabeled_t:s0 release
drwxr-xr-x. root root unconfined_u:object_r:unlabeled_t:s0 release-desc
# 修改文件属性
[root@D-WY-DEV8 ~]# chcon -R -t httpd_sys_content_t /mnt/nokia/htdocs
# 验证
[root@D-WY-DEV8 etc]# ls -Z /mnt/nokia/htdocs
drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 release
drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 release-desc