前文给大家介绍了FTP服务器的配置方法,今天给大家介绍下 HTTP文件服务器的配置方法。

前文参考:https://www.gbase.cn/community/post/4391

HTTP服务器配置

使用apache搭建HTTP文件服务器

1)安装apr和httpd

# rpm -ivh 
apr-1.3.9-3.el6_1.2.x86_64.rpm 
apr-util-1.3.9-3.el6_0.1.x86_64.rpm apr-util-ldap-1.3.9-3.el6_0.1.x86_64.rpm 
# rpm -ivh 
httpd-2.2.15-15.el6.x86_64.rpm 
httpd-manual-2.2.15-15.el6.noarch.rpm  httpd-tools-2.2.15-15.el6.x86_64.rpm

2)修改HTTP服务器默认配置

# vim /etc/httpd/conf/httpd.conf

修改服务器名称

# If your host doesn't have a registered DNS name, enter its IP address here.
# You will have to access it by its address anyway, and this will make 
# redirections work in a sensible way.
#ServerName www.example.com:80
ServerName 192.168.10.114:80

修改以下位置,将其中的"/var/www/html"修改为"/var/www/files"
也可直接使用"/var/www/html"作为文件存储位置,跳过这一步

# 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" 
DocumentRoot "/var/www/files"
#
# This should be changed to whatever you set DocumentRoot to.
#
#<Directory "/var/www/html">
<Directory "/var/www/files">

修改其它参数

# 是否使用memory-mapping,默认值on,挂载nfs系统时设为off
# EnableMMAP off
# 是否使用sendfile系统调用,默认值on,挂载nfs系统时设为off
# EnableSendfile off
# 连接超时,默认值为60
# Timeout 60

禁用长文件名截断,添加以下配置。

<IfModule autoindex_module>
 IndexOptions NameWidth=*
</IfModule>

或者

IndexOptions FancyIndexing VersionSort NameWidth*

注意:如果不禁用长文件名截断,由于Apache会返回不完整的文件名,会导致使用通配符方式加载HTTP文件时发生错误。

3)编辑默认欢迎页配置

# vim /etc/httpd/conf.d/welcome.conf

注释掉以下几行(默认如果html下没有默认页面将显示403错误页面)

#<LocationMatch "^/+$">
# Options -Indexes
# ErrorDocument 403 /error/noindex.html
#</LocationMatch>

4)关闭或配置防火墙

  • 关闭防火墙

停止防火墙服务

# service iptables stop
iptables:清除防火墙规则:                                 [确定]
iptables:将链设置为政策 ACCEPT:filter                    [确定]
iptables:正在卸载模块:                                   [确定]

查看防火墙是否在开机时自动启动

# chkconfig --list iptables
Iptables    0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭

禁止防火墙在开机时自动启动

# chkconfig iptables off
或   
# chkconfig iptables off --level 2345

设置后防火墙在开机时自动启动状态

# chkconfig --list iptables
Iptables    0:关闭  1:关闭  2:关闭  3:关闭  4:关闭  5:关闭  6:关闭
  • 配置防火墙

设置默认规则

# iptables -A INPUT -j DROP
# iptables -A FORWARD -j ACCEPT

开放HTTP端口

# iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT 
# iptables -I OUTPUT -p tcp -m tcp --sport 80 -j ACCEPT

保存防火墙设置

# iptables-save > /etc/sysconfig/iptables

5)启动httpd服务并设置为开机启动项

# service httpd start
正在启动 httpd:                                           [确定]
# chkconfig httpd on

6)将数据文件复制到/var/www/files(或/var/www/html)下

7)用浏览器访问http://192.168.10.114即可看到文件列表(前面配置的ServerName 192.168.10.114:80)

以上就是今天的内容,感谢阅读!