项目中经常会用到文件服务器你的是不是直接在当前目录下新建一个img目录来当做图片目录呢???
下面我来简单介绍下apache来做文件服务器的做法吧,基本的思路就是apache文件服务器单独一个服务器,然后我们如果有文件需要上传的话就在项目中通过sftp或者ftp的形式来传输就可以了(sftp的话推荐使用jsch,ftp的话就用ftp).
首先我们来部署apache文件服务器环境
所需文件apr-1.5.2.tar.gz,apr-util-1.5.4.tar.gz,httpd-2.4.17.tar.gz,pcre-8.12.tar.gz
1.安装 yum -y install gcc-c++
2.解压apr-1.5.2.tar.gz,apr-util-1.5.4.tar.gz,httpd-2.4.17.tar.gz,pcre-8.12.tar.gz
tar -zxvf apr-1.5.2.tar.gz,tar -zxvf apr-util-1.5.4.tar.gz,tar -zxvf httpd-2.4.17.tar.gz,tar -zxvf pcre-8.12.tar.gz
2.1安装apr
cd /apr-1.5.2
./configure --prefix=/usr/local/apr
如果apache rm: cannot remove `libtoolT': No such file or directory报这个错的话可以使用下面的方法
1、确认libtool是否已经安装,如果没有安装的话,则先安装libtool
# yum -y install libtool
2、分别执行以下三条命令:
# autoreconf –force –install
# libtoolize –automake –force
# automake –force –add-missing
再重新编译安装,问题解决!
在网上也看到有别的办法,但是我没有测试过,例如:
这时直接打开 configure,把 $RM “$cfgfile” 那行删除掉,重新再运行 ./configure 就可以了。
make && make install然后编译,这样的话/usr/local/apr就是你的apr的安装目录了
2.2安装apr-util
cd /apr-util-1.5.4
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr(注意:--with-apr=/usr/local/apr是上面安装apr的路径)
make && make install
2.3安装httpd
cd /httpd-2.4.17
./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mods-shared=most --enable-mpms-shared=all --with-mpm=event
安装如果报configure: WARNING: OpenSSL version is too old
no
checking whether to enable mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures
这个错的话可以
解决:
yum install openssl-devel
yum update openssl
然后重新执行命令
然后就可以make && make install
然后配置文件就都在/etc/httpd下面的httpd.conf了具体属性解释的话在这里就不说了
接下来给文件服务器创建一个用户并分配一个文件
useradd -d /home/ad_ftp -m ad_ftp
[root@ad3 home]# passwd ad_ftp
Changing password for user ad_ftp.
New password:
BAD PASSWORD: it is based on a dictionary word
Retype new password:
passwd: all authentication tokens updated successfully.
这个时候启动apache
/usr/local/apache/bin/apachectl start启动
然后在浏览器中输入服务器的地址,如果出现
It works!
<Directory "/home/ftp">
#
# 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 Indexes FollowSymLinks
Options None
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride None
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
将Options Indexes FollowSymLinks改成Options None这样的话如果用户访问到文件夹层的时候就会报
Forbidden
You don't have permission to access /test/test/ on this server.