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 服务,乱码问题解决。
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于