源码安装
> tar zxf httpd-2.2.27.tar.gz
> cd httpd-2.2.27
less INSTALL 或 less README 查看帮助
./configure --prefix=/application/apache2.2.27 --enable-deflate --enable-expires --enable-headers --enable-modules=most --enable-so --with-mpm=worker --enable-rewrite
1. make&&make install
2. yum install zlib zlib-devel -y
3. ln -s /application/apache2.2.27/ /application/apache
> /application/apache/apachectl -t #检测语法
> /application/apache/apachectl start #启动服务
> /application/apache/bin/apachectl graceful #平滑启动
> lsof -i :80 #检查端口
或者
> ps -ef | grep httpd #检查进程
浏览器访问服务器ip地址出现apache页面表示正常。
/usr/sbin/apachectl -l #查看编译模块
/usr/sbin/apachectl -M #查看编译模块
rpm -qa httpd
rpm -ql httpd #查看安装目录
DocumentRoot "/usr/local/ads" #主站根目录
优化:
Options -Indexes FollowSymLinks #Indexes前加-号,防止暴露根目录文件
添加站点:
<Directory "/var/html/">
Options -Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
指定访问的首页文件:
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
FQDN问题:
#ServerName www.example.com:80
ServerName 192.168.177.4:80
虚拟机主机:
部署多个站点,每个站点,希望用不同的域名和站点目录,或者是不同的端口,不同的IP。需要虚拟主机功能。一句话,一个http服务要配置多个站点,就需要虚拟主机。
虚拟机分类:
a.基于域名*****
b.基于端口
c.基于ip
所谓的基于XX,就是靠XX来区分不同的站点。支持各种混合,N多个虚拟主机。
虚拟主机配置:
域名 站点目录
www.sinjon.org /var/html/www
blog.sinjon.org /var/html/blog
bbs.sinjon.org /var/html/bbs
1. 打开/usr/local/apache2/conf/httpd.conf把下面语句前的#号去掉和添加如下内容
#Include conf/extra/httpd-vhosts.conf
<Directory "/var/html/">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
2. /usr/local/apache2/conf/extra/httpd-vhosts.conf 添加如下内容:
<VirtualHost *:80>
ServerAdmin 630527184@qq.com
DocumentRoot "/var/html/www"
ServerName www.baidu.com
ServerAlias baidu.com #别名
ErrorLog "logs/www-error.log"
CustomLog "logs/www-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin 630527184@qq.com
DocumentRoot "/var/html/blog"
ServerName blog.baidu.com
ErrorLog "logs/blog-error.log"
CustomLog "logs/blog-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin 630527184@qq.com
DocumentRoot "/var/html/bbs"
ServerName bbs.baidu.com
ErrorLog "logs/bbs-error.log"
CustomLog "logs/bbs-access_log" common
</VirtualHost>
基于端口:
/usr/local/apache2/conf/httpd.conf
Listen 80
Listen 8000
Listen 9000
/usr/local/apache2/conf/extra/httpd-vhosts.conf
NameVirtualHost *:80
NameVirtualHost *:8000
NameVirtualHost *:9000
<VirtualHost *:80>
.。。。。
</VirtualHost>
<VirtualHost *:8000>
</VirtualHost>
<VirtualHost *:9000>
</VirtualHost>
apache性能调优:
1、打开/usr/local/apache2/conf/httpd.conf把下面语句前的#号去掉
#Include conf/extra/httpd-mpm.conf
2、查看apache使用的什么工作模式,下面为prefork.c模式
cd /usr/local/apache2/bin
[root@ADSHttp2 bin]# ./apachectl -l
prefork.c
3、修改/usr/local/apache2/conf/extra/httpd-mpm.conf文件,找到preforkmodule修改
<IfModule mpm_prefork_module>
ServerLimit 20000
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 2500
MaxRequestsPerChild 0
</IfModule>
serverLimit最大为20000,需改大时要编译安装时指定,MaxClients 为最大连接进程数(客户端连接数)
配置文件 /usr/local/apache2/conf/httpd.conf
ServerRoot "/usr/local/apache2" #程序服务的路径
Listen 80
ServerAdmin you@example.com #支持人员邮箱
ServerName 172.23.2.31:80 #域名
DocumentRoot "/usr/local/ads" #站点根目录
<Directory "/usr/local/ads">
Options Indexes FollowSymLinks #Indexes 前加上-表示不列出站点文件
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<IfModule dir_module>
DirectoryIndex index.html #指定首页文件,添加多个用空格
</IfModule>
ErrorLog "|/usr/local/apache2/bin/rotatelogs /usr/local/apache2/logs/%Y%m%d_error.log 86400"
LogLevel warn #日志级别
<IfModule log_config_module>
LogFormat "2],[%A],[%h],[%{%Y-%m-%d %H:%M:%S}t],[http://%A%U],[%>s],[%b" common
LogFormat "%A],[%h],[%{%Y-%m-%d %H:%M:%S}t],[http://%A%U]" referer
LogFormat "%A],[%h],[%{%Y-%m-%d %H:%M:%S}t],[http://%A%U]" agent
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
<FilesMatch "\.(zip|apk)">
SetEnv IFILE 1
</FilesMatch>
<FilesMatch "\.(zip|apk|xml|crl|cer|ico)">
SetEnv http_IFILE 1
</FilesMatch>
<FilesMatch "\.(xml)">
SetEnv xml_IFILE 1
</FilesMatch>
CustomLog "|/usr/local/apache2/bin/rotatelogs /usr/local/ads_logs/DownloadLog/AppDownloadInfo_172.23.2.31_%Y%m%d_%H.log 3600 480" common env=IFILE
CustomLog "|/usr/local/apache2/bin/rotatelogs /usr/local/ads_logs/HttpConnectInfo/HttpConnectInfo_172.23.2.31_%Y%m%d_%H.log 3600 480" referer env=http_IFILE
CustomLog "|/usr/local/apache2/bin/rotatelogs /usr/local/ads_logs/AutoDownloadListLog/AutoDownloadListinfo_172.23.2.31_%Y%m%d_%H.log 3600 480" agent env=xml_IFILE
</IfModule>
DefaultType text/plain
Include conf/extra/httpd-mpm.conf
网友评论