apache搭建图片预览服务

apache安装

  • yum安装
yum install httpd -y

  • 启动,并添加开机启动
systemctl start httpd
systemctl enable httpd

  • 打开浏览器 测试 127.0.0.1

备注:端口默认是80

httpd设置

打开apache的主配置文件

vim /etc/httpd/conf/httpd.conf
  • 端口设置

找到第42行Listen,这里可以设施服务的端口

#
# 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 9000

#
# Dynamic Shared Object (DSO) Support
#
  • 目录设置

找到第119行至131行,将DocumentRoot、Directory设置成自己的文件或图片仓库目录,如果我的目录地址是/home/file

#
# 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 "/home/file"

#
# Relax access to content within /var/www.
#
<Directory "/home/file">
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>

# Further relax access to the default document root:
<Directory "/home/file">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #

这样我们就可以直接浏览我们仓库的文件目录或者图片了

  • 目录权限设置

如果没有具体的访问文件,就会默认跳转到根目录,其它所有的文件信息都能看到,这样文件就会暴露,我们可以设置目录禁止访问:

    #
    Options Indexes FollowSymLinks
    #

将Options Indexes FollowSymLinks修改为Options FollowSymLinks,其实就是将Indexes去掉,Indexes表示若当前目录没有index.html就会显示目录结构。

  • 目录编码设置

当目录中存在中文的时候,默认的httpd配置会显示乱码,我们可以修改httpd的编码

# Further relax access to the default document root:
<Directory "/home/file">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options FollowSymLinks
    IndexOptions Charset=GB2312
    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride None

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>

在Options FollowSymLinks下加IndexOptions Charset=GB2312这一行配置就可以了,重启httpd服务,乱码问题解决。


标题:apache搭建图片预览服务
作者:upaths
地址:http://noyil.com/apache-install