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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM