centos使用httpd搭建文件下载服务器教程

前言
工作中遇到需求,需要搭建一个HTTP文件服务器来共享文件。
需求比较简单:共享一个目录下的文件,让其他人能够通过HTTP方式下载。
之前使用Python内置的HTTP文件服务功能,但效果不佳。所以更换方案,采用httpd搭建。

一、配置内网repo

wget --ftp-user=xxx --ftp-password=xxx ftp://xxx/centos7/centos7.sh
chmod 777 centos7.sh
./centos7.sh

二、安装httpd

执行命令
yum install httpd

三、配置httpd

vi /etc/httpd/conf/httpd.conf

3.1 修改端口号

# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses.
#
# Listen 12.34.56.78:80
Listen 80 # 根据实际情况修改

3.2 修改目录权限

#
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other
# <Directory> blocks below.
#
<Directory />
AllowOverride none
# Require all denied 默认设置,拒绝所有访问请求
Options All # 显示目录结构,以便用户浏览下载
</Directory>

3.3 修改共享目录

#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/data/" # 根据实际情况修改
 
#
# Relax access to content within /var/www.
#
<Directory "/data"> # 根据实际情况修改
AllowOverride None
# Allow open access:
# Require all granted
# Allow from all
</Directory>
 

四、修改文件目录权限

权限不对,会出现无权限访问的错误。目录名请根据实际情况修改。
chmod -R 755 apks/ # 根据实际情况修改
chmod -R 755 shared/ # 根据实际情况修改

五、启动httpd服务

systemctl start httpd

六、其他常用命令

重启httpd服务
systemctl start httpd
原文地址:https://www.cnblogs.com/xiaoming/p/15619234.html