cixiren 发表于 2016-12-31 07:49:59

Apache 文件服务器

Linux下环境搭建:
 下载apache 服务器安装文件
# wget http://mirrors.cnnic.cn/apache//httpd/httpd-2.4.17.tar.gz
或者从http://httpd.apache.org/上下载httpd-2.4.17.tar.gz,上传到linux主机,然后开始安装。
 
解压tar -zxvf httpd-2.4.17.tar.gz,完成之后,会在当前目录出现一个httpd-2.4.17目录,然后顺序执行如下命令
cd httpd-2.4.17
设置安装参数,命令如下:
./configure --prefix=/usr/local/apache --enable-module=so
其中prefix参数指明将apache安装到/usr/local/apache目录
提示以下错误:
configure: error: APR not found. Please read the documentation.
 
下载依赖包
1出现找不到apr
# wget http://archive.apache.org/dist/apr/apr-1.4.5.tar.gz
解压
# tar -zxvf apr-1.4.5.tar.gz
然后顺序执行如下命令
# cd apr-1.4.5
# ./configure --prefix=/usr/local/apr
# make
# make  install
 
2,后面可能还会出现找不到apr-util
# wget http://archive.apache.org/dist/apr/apr-util-1.3.12.tar.gz
解压
# tar -zxvf apr-util-1.3.12.tar.gz
然后顺序执行如下命令
# cd apr-util-1.3.12
#./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make
# make  install
 
3,后面可能还会出现找不到pcre
# wget http://sourceforge.net/projects/pcre/files/pcre/8.37/pcre-8.37.tar.gz
解压
# tar -zxvf pcre-8.37.tar.gz
然后顺序执行如下命令
# cd pcre-8.37
# ./configure --prefix=/usr/local/pcre
# make
# make  install
 
设置安装参数,命令如下:
./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre
最后编译,安装;顺序执行如下命令:
make
make install
 
启动 apache 服务器
进去apache 安装目录(/usr/local/apache)下 cd bin
# ./apachectl start
 
如果报下面错误
httpd: Could not reliably determine the server's fully qualified domain name
解决方案:在conf/http.conf文件里面加上
ServerName localhost:80  (要和Listen 80的端口一致)
访问 http://ip:端口
如果页面显示“It works!”,即表示apache已安装并启动成功。
停止apache 服务器
# ./apachectl stop
查看apache服务占用的端口
ps aux |grep apache
 
将apache 设置为开机启动的方法:
方法一:将apache 添加成一个服务然后开机启动
第一步:
cp /usr/local/apache/bin/apachectl /etc/init.d/apache
第二步:
使用编辑器打开/etc/init.d/apache文件,并在第一行#!/bin/sh下增加两行文字如下
# chkconfig: 35 70 30
# description: Apache
 
第三步:
chkconfig --add apache
如果跳过第二步直接执行第三步会报如下错误   service apache does not support chkconfig
第四步:
启动 apache 服务
service apache start
 
方法二:向/etc/rc.local中添加/usr/local/apache/bin/apachectl start 保存退出之后重启系统
 
Windows下环境搭建:
 
 
http.conf配置文件设置:
Listen 80   表示主机是监听80的端口 
ServerName http//localhost:80 #主站点名称(网站的主机名)
DocumentRoot "/usr/local/apache/htdocs" #主站点的网页存储位置

Alias /test/ "/data/test/var/applicationSheet/"   
#访问时可以输入:http//localhost/test/
<Directory "/data/test/var/applicationSheet/">
Order Allow,Deny #allow和deny的优先级别。
Allow from all #允许all访问
deny from 192.168.0.1 #阻止192.168.0.1访问
</Directory> 
 apache下设置不显示目录列表的做法
a、要禁止 Apache 显示目录结构列表,只需将 Option 中的 Indexes 去掉即可。

<Directory />
Options Indexes FollowSymLinks#------>Options FollowSymLinks
AllowOverride None
</Directory>

 
b、  在Options Indexes FollowSymLinks在Indexes前面加上 – 符号。
          即: Options -Indexes FollowSymLinks
        【备注:在Indexes前,加 + 代表允许目录浏览;加 – 代表禁止目录浏览。】
 
相关链接:http://blog.sina.com.cn/s/blog_66c183b3010102ql.html 
常见问题:
1、apache出现You don't have permission to access / on this server. 提示(解决方法)
<Directory />
    Options Indexes FollowSymLinks
    AllowOverride None
</Directory>
 

<!--StartFragment -->
   有时间查查怎么在apache 防盗链控制文件服务器资源的权限控制。
   http://blog.chinaunix.net/uid-21266384-id-186472.html


 
 
页: [1]
查看完整版本: Apache 文件服务器