Apache服务器的安装与配置和总结
Apache服务器的安装与配置1.rpm包apache
(1).检查是否安装httpd: rpm -qa |grep httpd
(2).安装httpd服务器: rpm -ivh httpd-*.rpm
(3).Apache服务的配置文件
/etc/httpd/ //Apache服务器的根目录
/etc/httpd/conf/httpd.conf //Apache服务器的主配置文件
/var/www/html //Apache服务器的文档根目录
/etc/init.d/httpd//Apache服务器的启动脚本文件
/var/log/httpd/access_log //Apache服务器的访问日志文件
/var/log/httpd/error_log //Apache服务器的错误日志文件
(4)./etc/httpd/conf/httpd.conf的配置参数:
Apache的全局配置
ServerRoot /etc/httpd//Apache的根目录
PidFile run/httpd.pid//保存Apache父进程ID
Timeout 120 //客户端超过120秒没连接上服务器,强制断线
KeepAlive on //允许客户端同时提出多个请求
KeepAlive Timeout 15//客户端请求15秒还没有发出,则断线
MinSpareServers 5//最少有5个闲置httpd进程监听用户请求
MaxSpareServers 20//最大的闲置httpd进程为20
StartServers 8 //启动时打开的httpd进程数目
MaxClients 256 //限制客户端的同时最大连接数目
MaxRequestPerChild//限制每个httpd进程可以完成的最大任务数目
Listen 80 //Apache服务器监听的端口
LoadModule auth_basic_module modules/mod_auth_basic.so //加载DSO模块
ExtendedStatus On//检测Apache的状态作息
Apache主服务器配置
ServerAdmin root@localhost //管理员的电子邮件地址
ServerName www.server.com:80 //主机名称,即域名
DocumentRoot "/var/www/html" //Apache服务器网页存放地址
Options FollowSymLinks
AllowOveride None
//Apache根目录的访问权限和访问方式
Options Indexs FollowSymLinks
AllowOveride None
Order allow,deny
Allow from all
//设置Apache服务器网页文件存放目录的访问权限
UserDir disable
#UserDir public_html
//设置用户在自己public_html目录下建立主页
DirectoryIndex index.html index.html.var //设置预设首页
AccessFileName.htaccess//设置Apache目录访问权限的控制文件
Order allow,deny //防止用户看到以".ht"开头的文件,保 Deny from all护.htaccess、.htpasswd的内容
TypesConfig /etc/mime.types //指定存放MIME文件类型的文件
DefaultType text/plain//当Apache不能识别某种文件类型时,自动当成文 本文件处理
HostnameLookups Off//设为on时每次都会向DNS服务器要求解析该IP ErrorLog logs/error_log//指定错误发生时记录文件的位置
LogLevel warm //指定警告及以上等级的信息会被记录在案
CustomLog logs/access_log combined //设置存取文件记录采用combined模式
ServerSignature On//服务器出错所产生的网页会显示Apache的版本号 、主机、连接端口等信息
Alias /icons/"var/www/icons/"
Options Indexes MultiViews
AllowOveride None
Order allow,deny
Allow from all
//定义一个图标虚拟目录,并设置访问权限
ScriptAlias /cgi-bin/"/var/www/cgi-bin/"
AllowOveride None
Options None
Order allow,deny
Allow from all
//设置脚本文件目录
AddType text/html.shtml
AddOutputFilter INCLUDES.shtml //使用动态页面
ErrorDocument 500 "The server made a boo boo"
ErrorDocument 404 "missing.html"
ErrorDocument 404 "/cgi-bin/missing_handler.pl"
ErrorDocument 402 http://www.example.com/subscription_info.html
//Apache支持3种格式的错误信息显示方式:纯文本、内部链接和外部链接。
BrowserMatch "Mozilla/2" nokeepalive
BrowserMatch "MSIE 4\.0b2;" nokeepalive downgrade-1.0 force-response-1.0
//如果浏览器符合这两种类型,则不提供keepalive支持
BrowserMatch "4\.0" force-response-1.0
BrowserMatch "java/1\.0" force-response-1.0
BrowserMatch "JDK/1\.0" force-response-1.0
//如果浏览器是这三种类型,则使用"HTTP/1.0"回应
虚拟主机配置
NameVirtualHost *:80//设置虚拟主机的名字和监听端口
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /www/docs/dummy-host.example.com
ServerName dummy-host.example.com
ErrorLog logs/dummy-host.example.com-error_log
CustomLog logs/dummy-host.example.com-access_log common
(5).配置虚拟目录
为/var/www/html建立虚拟目录
在httpd.conf的全局配置中添加:
Alias /test/ "/var/www/html/"
在Apache主服务中添加
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
//为/test目录设置权限
(6).用户身份认证
创建用户名和密码
htpasswd -mb .htpasswd user1 123
认证方式
AuthType Basic //采用的加密方式是mod_auth提供的Basic
AuthName "Restricted Files" //设置使用认证的领域
AuthUserFile /usr/local/apache/passwd/.htpasswd
Require user clinuxer //设置允许访问的用户
实例:创建一个用户clinuxer
cd /var/www/html
/usr/bin/htpasswd -c /usr/local/apache/passwd/.htpasswd
在httpd.conf文件中设置该目录允许采用.htaccess进行用户身份认证
vi /etc/httpd/conf/httpd.conf
Alias /test "/var/www/html/"
Option Indexes MultiViews //允许列目录
AllowOverride AuthConfig //启用用户身份认证
Order deny,allow
Allow from all //允许所有用户访问
在/var/www/html目录下新建一个.htaccess文件
touch .htaccess
vi .htaccess
AuthName "Test Zone"
AuthType Basic
AuthUserFile /usr/local/apache/passwd/.htpasswd
require user clinuxer
(7).日志统计分析
编辑Webalizer配置文件
vi /etc/webalizer
LogFile /var/log/httpd/access_log
OutputDir /var/www/useage
Incremental yes
配置虚拟目录
vi /etc/httpd/conf/httpd.conf
Alias /webalizer/ "/var/www/usage/"
AllowOverride AuthConfig
Order deny,allow
Allow from all
创建.htaccess文件
vi /var/www/usage/.htaccess
AuthName "Test Zone"
AuthType Basic
AuthUserFile /usr/local/apache/passwd/.htpasswd
require user clinuxer
创建clinuxer用户
htpasswd -mb .htpasswd clinuxer 123
生成统计文档
在虚拟终端:webalizer
客户端访问
http://ServerName或IP/webalizer
(8).Apache服务器启动,停止,重启
service httpd start
service htttd stop
service httpd restart
2.源码安装Apache
(1).用tar命令释放源代码包
tar zxvf httpd-*.tar.gz
(2).使用./configure命令进行编译前的配置工作
./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite
(3).编译
make
(4).运行
make install
(5)./usr/local/apache2中的子目录
bin //保存Apache服务器运行和管理所需的执行程序
lib //保存Apache服务器运行所需的库文件
conf //保存Apache服务器的配置文件
htdocs //Apache服务器的文档根目录
manual //Apache服务器的帮助手册文件
man //Apache服务器的手册页文件
logs //Apache服务器的日志文件
(6).使用apachectl脚本启动,停止,重启服务器
/usr/local/apache2/bin/apachectl start
/usr/local/apache2/bin/apachectl stop
/usr/local/apache2/bin/apachectl restart
页:
[1]