作者:独笔孤行
公众号:云实战
官网:http://anyamaze.com
前言
HTTP是超文本传输协议,通过http协议即可搭建网站,提供访问web,也可以实现文件的共享传输。实现文件传输,可直接使用httpd或SimpleHTTPServer服务,
一、安装httpd
执行安装httpd命令
二、配置httpd
所有修改在/etc/httpd/conf/httpd.conf配置文件中
vi /etc/httpd/conf/httpd.conf
2.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 # 根据实际情况修改
2.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>
2.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 "/var/www/html" # 根据实际情况修改
......
<Directory "/var/www/html"> #根据实际情况修改
Options Indexes FollowSymLinks
IndexOptions Charset=UTF-8 #设置UTF-8字符集,防止中文乱码
AllowOverride None
Require all granted
</Directory>
2.4在存放目录/var/www/html中生成测试文件
echo "Hello World" > /var/www/html/test.conf
2.5 移除默认页面
mv /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.d/welcome.conf.bak
三、确认文件目录权限
默认目录/var/www/html/权限无需修改,若是新建目录,需设置访问权限755,否则无法访问。
chmod -R 755 /data # 根据实际情况修改/data目录
四、启动httpd服务
systemctl start httpd
systemctl enable httpd
五、访问http文件
默认可直接打开,若需要下载,可通过wget命令下载所需文件
更多咨询