您的位置:首页 > 运维架构 > Apache

apache配置搭建

2017-01-04 00:06 134 查看
软件包下载:
wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.4.25.tar.gz
wget http://mirror.bit.edu.cn/apache/apr/apr-1.5.2.tar.gz
wget http://mirror.bit.edu.cn/apache/apr/apr-util-1.5.4.tar.gz

yum install -y gcc autoconf automake make pcre pcre-devel openssl openssl-devel

tar xvf apr-1.5.2.tar.gz
cd apr-1.5.2
./configure
make
cd ..

tar xvf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4
./configure --with-apr=/usr/local/apr
make
cd ..

tar xvf httpd-2.4.25.tar.gz
cd httpd-2.4.25
./configure --prefix=/usr/local/apache2 --enable-so --enable-ssl --enable-rewrite --with-mpm=worker --with-suexec-bin --with-apr=/usr/local/apr/
make
cd ..

--prefix //指定安装目录
--enable-so //开启模块化功能
--enable-ssl //支持ssl加密
--enable-rewrite //支持地址重写
--with-mpm //设置http工作方式
--with-suexec-bin //支持suid,sgid
--with-apr //指定apr程序绝对路径

参数
/usr/local/apache2/bin/apachectl
-t/configtest  检测http配置文件语法是否正确
graceful 启动httpd,不中断现有的http连接请求
graceful-stop 关闭httpd,不中断现有的http连接请求

配置文件解析
ServerRoot "/usr/local/apache2"  //httpd 安装目录
LoadModule foo_module modules/mod_foo.so //编译时加--enable-so,格式LoadModule 模块 模块文件名称
ServerAdmin you@example.com //当网站出问题,发的解决问题邮箱
ServerName www.example.com //网站域名
DocumentRoot "/usr/local/apache2/htdocs" //web服务器的根目录
ErrorLog "logs/error_log" //定位服务器错误日志
Include conf/extra/httpd-mpm.conf //在apache主配置文件中加载其它配置文件
Options None //不启用任何额外功能
ALL:开启除MultiViews之外的所有选项

ExecCGI:允许指定目录下的所有CGI脚本

FollowSymlinks:允许指定目录下的文件链接到目录外的文件或目录

Indexes:如果URL对应Options目录下找不到DirectoryIndex指定的首页文档,则apache将会把当前目录的所有文件索引出来

Order指令:
先检测允许,在检测拒绝,默认允许
Order deny,allow
Deny from all

eg:
Order Allow,Deny
allow from 192.168.1.10

IfDefine容器
在httpd启动时测试条件为真,才会被处理 需要通过httpd -D定义
<IfDefine>指令</IfDefine>
eg:
<IfDefine MemCache>
LoadModule mem_cache_module modules/mod_mem_cache.so
</IfDefine>
<IfDefine UseCache>LoadModule cache_module modules/mod_cache.so</IfDefine>

IfModule容器
仅在条件满足时才会处理的指令
<IfModule[!] 模块>指令</IfModule>
eg:
<IfModule unixd_module>
User daemon
Group daemon
</IfModule>
加载unixd_module模块后,User daemon与Group daemon才会被处理

Directory容器
用于特定文件系统,子目录以及目录下的内容
<Directory directory-path>指令</Directory> 路径可以用~正则表达式匹配
<Directory "/usr/local/apache2/htdocs">
Options Indexs FollowSymLinks
</Directory>
<Directory ~ "^/www/[0-9]{3}">AllowOverride None
</Directory>
Location容器<Location URL-path|URL>指令</Location>加~使用正则表达式
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  apache 配置记录