linux apache服务器配置与管理
时间:2007-09-24 来源:ank
apache服务器配置与管理
文件与目录
/etc/httpd
d-----------conf
-----------httpd.conf -->主要的配置文件
-----------magic
d-----------conf.d
-----------BackupPc.conf
-----------manual.conf
-----------perl.conf
-----------php.conf
-----------proxy_ajp.conf
-----------python.conf
-----------squid.conf
-----------ssl.conf
-----------system-config-httpd.conf
-----------webalizer.conf
-----------welcome.conf
l-----------logs ->../../var/log/httpd
l-----------modules ->../../usr/lib/httpd/modules
l-----------run ->../../var/run /etc/www -->apache web站点文件的目录
d-----------cgi-bin
d-----------error
d-----------html -->web站点的web文件
d-----------icons
d-----------usage - /etc/log/httpd
-------------access_log
-------------error_log
-------------ssl_access_log
-------------ssl_error_log
-------------ssl_request_log
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<httpd.conf文件的设定>
1全局环境设定
#11111111111111111111111111111111111111111111111111111111111111111111111111111111
ServerTokens OS
ServerRoot "/etc/httpd" -->服务器配置文件的及日志文件的位置
#ScoreBoardFile run/httpd.scoreboard -->指定服务器内部进程信息的日志文件
PidFile run /httpd.pid -->用来指定httpd.pid的位置,此文件记录httpd进程执行时的id
Timeout 300 -->指定网站响应的时间,以s位单位,超过这段时间乃未收到或未送出速据,就断开连接
KeepActive On -->启用此项可以提高访问的性能,启用表示允许保持连接,最好让每次连接能提出多个请求,避免每请求一次文件,就跟服务器建立一次连接
MaxKeepAliveRequest 100 -->每次连接可提出请求的数量,设为0表示不限,默认为100
KeepAliveTimeout -->连续两个请求的间隔时间,如果超过10s还未收到,则视为连接中断 ##mpm specific #prefork mpm
<IfModule prfork.c>
StartServer 8 -->服务器启动时,会执行8个httpd进程
MinSpareServer 5
MaxSpareServer 20
MaxClients 150
MaxRequestsPerChild 1000 -->当浏览器连接网页后,限制每个子进程在终止前所能提出的请求数量
</IfModule> #worker mpm
<IfModule worker.c>
startserver 2
maxclients 150
minsparethreads 100
maxsparethreads 75
threadsperchild 25
maxrequestsperchild 0
</IfModule> #perchile mpm
<IfModule perchild.c>
numservers 5
startthreads 5
minsparethreads 5
maxsparethreads 10
maxthreadsperchild 20
maxrequestsperchild 0
</IfModule>
Listen 80 -->默认情况下,httpd除了监听默认的通信端口还能监听的其他端口号
Include conf.d/*.conf
LoadModule access_module modules/mod_access.so
L...
L...
L...
L...
L...
L...
L...
-->以上是LoadModule用在服务器启动时动态加载的模块
<Ifmodule prefork.c>
LoadModule cgi_module modules/mod_cgi.so
</Ifmodule>
<IfModule worker.c>
LoadModule cgid_module modules/mod_cgi.so
</Ifmodule>
#ExtendedStatus On -->启动此项可让服务器生成完整的状态信息,关闭,则生成基本的信息
#主要的服务器配置
#22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
User apache
Group apache -->设置httpd用哪个帐号和用户组来启动,默认是用apache帐号与用户组
serverAdmin root@localhost
#ServerName 192.168.0.6 -->设置主机的名称,此名称会被送到远程连接程序,以取代安装apache server主机的真是名称,若主机并没有已注册的名称,则可以使用ip地址,默认是localhost,80为指定被指定的监听的端口号
UseCanonicalName Off
DocumentRoot "/var/www/html" -->此为指定apahce 存放网页的根目录位置 #以下是<Directory></Directory>是设置目录的访问,<Location></Location>是设置URL的访问权限
<Directory> -->设置根目录
Options FollowSysLinks
AllowOverride None
</Directory>
<Directory "/var/www/html"> -->设置服务器网页的根目录,默认为/var/www/html
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
allow from all
</Directory>
<LocationMatch "^/$>
Options-indexes
ErrorDocument 403 /error/noindex.html
</LocationMatch>
<IfModule mod_userdir.c>
UserDir disable
#UserDir public_html -->每个该服务器帐号都可以在自己的Home下建立个人网站
</IfModule>
<Directory /home/*/public_html> -->
allowOverride FileInfo AuthConfig Limit
Options MutiViews Indexes SymLinksIfOwnerMatch INcludesNoEexc
<Limit GET POST OPTIONS>
Order allow,deny
Alloe from all
</Limit>
<LimitExcept GET POST OPTINOS>
Order deny,allow
Deny from all
</LimitExcept>
</Directory>
DirectoryIndex index.htm default.asp -->设置每个目录中默认的网页文件名称,排在前面优先 AccessFileName .htaccess -->指定保护目录设置文件的文件名称,以下是个例子
AuthUserFile /home/zjz/.htpasswd -->指定密码文件的位置
AuthName "Private directory" -->在请求输入密码是出现的提示
AuthType Basic -->设置身份验证 Request valia-user -->设置可访问此目录的用户
<File ~"^\.ht"> -->设置.ht*文件的访问权限
Order allow ,deny
Deny from all
</Files> TypesConfig /etc/mime.types -->设置各种文件类型的关联的位置
DefaultType text/plain -->当无法识别文件类型时,则当成文本处理
<Ifmodule mod_mime_magic.c> -->此模块可让服务器根据文件的内容来判断文件类型
MIMEMagicFile conf/magic
</IfModule>
HostnameLookups Off -->记录连接到该网站的主机ip
ErrorLog logs/error_log -->记录浏览器加载网页发生的错误,以及关闭或启动httpd的信息
LogLevel warn -->设置要存入error_log文件中的下消息等级 LogFormat....
LogFormat.....
LogFormat...... -->设置每条记录的格式 CustomLog logs/access_log combined -->访问记录的位置
#CustomLog logs/referer_log referer -->记录浏览者通过本网站所连接出去的网址,使用referer格式
CustomLog logs/agent_log agent -->记录浏览者连接到本网站所使用的网页浏览器版本与种类,使用agent格式
#customLog logs/access_log combined -->若将以上记录都放在一个文件中,则可使用combined格式
ServerSignature On -->server会自动生成网页(错误消息) Alias /icons/ "/var/www/icons" -->为某一目录建立别名
<Directory>
Options Indexes Muitiviews
AllowOverride None
Order allow,deny
alloe from all
</Directory>
Alias /manual/ "/var/www/manual"
<Directory>
Options Indexes Muitiviews
AllowOverride None
Order allow,deny
alloe from all
</Directory>
<IfModule mod_dav_fs.c>
</IfModule> ScriptAlias /cgi-bin/ "/var/www/cgi-bin" -->为script程序的目录设置别名,此目录中的文件会被视为可执行
<IfModule mod_cgid.c>
Scriptsock run/httpd.cgid
</IfModule>
<Dirctory "/var/www/cgi-bin">
AllowOverride None
Options ExecCGI
Order allow ,deny
Allow from all
<Directory> IndexOptions FancyIndexing VersionSort NameWidth=* -->当找不到index.htm等时将会显示列表 AddIcon
..
..
...
...
..
..
..
.
..
... -->定义每种文件类型的小图标
Default /icons/unknow.gif ReadmeName README.htm -->此文件会显示在文件的结尾,表示需要自己建立README.html
HeaderName README.htm -->此文件会显示在文件的开头,表示需要自己建立README.html
IndexIgnore .??~#$#^%& -->遇到这种文件不要列出来
AddEncoding x-compress Z
AddEncoding x-gzip gz tgz -->当遇到此扩展名,自动压缩 #以下对语言,字符等的配置
addLanguage da.dk
...
...
...
...
...
...
...
...
... AddHandler cgi-script.cgi -->设置遇到某些有扩展名的文件处理,遇到.cgi,当作cgi-script处理
..
..
.. #ErrorDocument 500 "the server made a boo boo"
#...
#... Alias /error/ "/var/www/error" #处理错误,缓存and so on.. #虚拟主机配置
#333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333
#virtual host
<VrualHost *>
ServerSignature email
DirectoryIndex index.htm index.html default.asp index.asp
LogLevel warn
HostNameLookups off
</VirtualHost> <Directory "/">
Options FollowSymLinks
AllowOverride None
</Directory> <Directory "/var/www/html">
Options FollowSymLinks
AllowOverride None
allow from from all
order allow ,deny
</Directory> <Directory "/var/www/icons">
Options FollowSymLinks
AllowOverride None
allow from from all
order allow ,deny
</Directory> <Directory "/var/www/cgi-bin">
Options FollowSymLinks
AllowOverride None
allow from from all
order allow ,deny
</Directory> #一个例子
<VirtualHost 192.126.2.5>
ServerName www.linxe.com
ServerAdmin [email protected]
DocumentRoot /Group/myimages/html
Errorlog logs/groups/logs/error_log
<VirtualHost> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For example
1>配置虚拟主机
基于ip地址的虚拟主机
1:ip地址相同,port不同
[]#cd /etc/httpd
[]#mkdir vipname.d
[]#mkdir /var/www/vipname_sameip1
[]#mkdir /var/www/vipname_sameip2
[/etc/httpd/vipname.d]#vim vipname_sameip.conf
Listen 81
Listen 8100 <VirtualHost 192.168.8.2:81>
Serversignature email
DocumentRoot /var/www/vipname_sameip1
DirectoryIndex index.html
LogLevel warn
HostNameLookups off
</VirtualHost> <VirtualHost 192.168.8.2:8100>
Serversignature email
DocumentRoot /var/www/vipname_sameip2
DirectoryIndex index.html
LogLevel warn
HostNameLookups off
</VirtualHost>
[]#vim /etc/htppd/httpd.conf
#结尾加上以下语句
include /vipname.d/*.conf
[]#service httpd restart
end
2:ip地址不同,port相同
只有一块物理网卡
eth0通过命令变为eth0:0和eht0:1同时捕获多个ip
ip1:192.168.01,IP2:192.168.0.2 #建立目录
[]#mkdir -p /var/www/vipname_sameport1
[]#mkdir -p /var/www/vipname_sameport2 #模块设定
[/etc/httpd/vname.d]#vim vipname_sameport.conf <VirtualHost 192.168.0.1:81>
Serversignature email
DocumentRoot /var/www/vipname_sameiport1
DirectoryIndex index.html
LogLevel warn
HostNameLookups off
</VirtualHost> <VirtualHost 192.168.0.2:81>
Serversignature email
DocumentRoot /var/www/vipname_sameiport2
DirectoryIndex index.html
LogLevel warn
HostNameLookups off
</VirtualHost> #写入配置模块
[]#vim /etc/httpd/httpd.conf
include /vipname.d/*.conf
[]#service httpd restart
2>基于名称的虚拟主机配置
3>动态虚拟寻主机的配置
4>组织和管理个人站定
[]#cd /home/ank
[]#mkdir public_html
[]#chmod 711 public_html
[]#chown ank public_html
[]#chgrp ank public_html
[]#vim /etc/httpd/conf/htttpd.conf
<?很郁闷,我这样做了可就时不会来,不知道哪里错了>
5>配置web目录
accessFilneName .htaccess
<Directory "/var/www/html"> -->设置默认路径 <Directory /var/www/html/ank>
Order allow,deny
allow from all
</Directory>
6>访问控制
order deny,allow -->order用来指定先后顺序
Allow from all
7>设置url路径名 8>验证web用户(略)
文件与目录
/etc/httpd
d-----------conf
-----------httpd.conf -->主要的配置文件
-----------magic
d-----------conf.d
-----------BackupPc.conf
-----------manual.conf
-----------perl.conf
-----------php.conf
-----------proxy_ajp.conf
-----------python.conf
-----------squid.conf
-----------ssl.conf
-----------system-config-httpd.conf
-----------webalizer.conf
-----------welcome.conf
l-----------logs ->../../var/log/httpd
l-----------modules ->../../usr/lib/httpd/modules
l-----------run ->../../var/run /etc/www -->apache web站点文件的目录
d-----------cgi-bin
d-----------error
d-----------html -->web站点的web文件
d-----------icons
d-----------usage - /etc/log/httpd
-------------access_log
-------------error_log
-------------ssl_access_log
-------------ssl_error_log
-------------ssl_request_log
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<httpd.conf文件的设定>
1全局环境设定
#11111111111111111111111111111111111111111111111111111111111111111111111111111111
ServerTokens OS
ServerRoot "/etc/httpd" -->服务器配置文件的及日志文件的位置
#ScoreBoardFile run/httpd.scoreboard -->指定服务器内部进程信息的日志文件
PidFile run /httpd.pid -->用来指定httpd.pid的位置,此文件记录httpd进程执行时的id
Timeout 300 -->指定网站响应的时间,以s位单位,超过这段时间乃未收到或未送出速据,就断开连接
KeepActive On -->启用此项可以提高访问的性能,启用表示允许保持连接,最好让每次连接能提出多个请求,避免每请求一次文件,就跟服务器建立一次连接
MaxKeepAliveRequest 100 -->每次连接可提出请求的数量,设为0表示不限,默认为100
KeepAliveTimeout -->连续两个请求的间隔时间,如果超过10s还未收到,则视为连接中断 ##mpm specific #prefork mpm
<IfModule prfork.c>
StartServer 8 -->服务器启动时,会执行8个httpd进程
MinSpareServer 5
MaxSpareServer 20
MaxClients 150
MaxRequestsPerChild 1000 -->当浏览器连接网页后,限制每个子进程在终止前所能提出的请求数量
</IfModule> #worker mpm
<IfModule worker.c>
startserver 2
maxclients 150
minsparethreads 100
maxsparethreads 75
threadsperchild 25
maxrequestsperchild 0
</IfModule> #perchile mpm
<IfModule perchild.c>
numservers 5
startthreads 5
minsparethreads 5
maxsparethreads 10
maxthreadsperchild 20
maxrequestsperchild 0
</IfModule>
Listen 80 -->默认情况下,httpd除了监听默认的通信端口还能监听的其他端口号
Include conf.d/*.conf
LoadModule access_module modules/mod_access.so
L...
L...
L...
L...
L...
L...
L...
-->以上是LoadModule用在服务器启动时动态加载的模块
<Ifmodule prefork.c>
LoadModule cgi_module modules/mod_cgi.so
</Ifmodule>
<IfModule worker.c>
LoadModule cgid_module modules/mod_cgi.so
</Ifmodule>
#ExtendedStatus On -->启动此项可让服务器生成完整的状态信息,关闭,则生成基本的信息
#主要的服务器配置
#22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
User apache
Group apache -->设置httpd用哪个帐号和用户组来启动,默认是用apache帐号与用户组
serverAdmin root@localhost
#ServerName 192.168.0.6 -->设置主机的名称,此名称会被送到远程连接程序,以取代安装apache server主机的真是名称,若主机并没有已注册的名称,则可以使用ip地址,默认是localhost,80为指定被指定的监听的端口号
UseCanonicalName Off
DocumentRoot "/var/www/html" -->此为指定apahce 存放网页的根目录位置 #以下是<Directory></Directory>是设置目录的访问,<Location></Location>是设置URL的访问权限
<Directory> -->设置根目录
Options FollowSysLinks
AllowOverride None
</Directory>
<Directory "/var/www/html"> -->设置服务器网页的根目录,默认为/var/www/html
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
allow from all
</Directory>
<LocationMatch "^/$>
Options-indexes
ErrorDocument 403 /error/noindex.html
</LocationMatch>
<IfModule mod_userdir.c>
UserDir disable
#UserDir public_html -->每个该服务器帐号都可以在自己的Home下建立个人网站
</IfModule>
<Directory /home/*/public_html> -->
allowOverride FileInfo AuthConfig Limit
Options MutiViews Indexes SymLinksIfOwnerMatch INcludesNoEexc
<Limit GET POST OPTIONS>
Order allow,deny
Alloe from all
</Limit>
<LimitExcept GET POST OPTINOS>
Order deny,allow
Deny from all
</LimitExcept>
</Directory>
DirectoryIndex index.htm default.asp -->设置每个目录中默认的网页文件名称,排在前面优先 AccessFileName .htaccess -->指定保护目录设置文件的文件名称,以下是个例子
AuthUserFile /home/zjz/.htpasswd -->指定密码文件的位置
AuthName "Private directory" -->在请求输入密码是出现的提示
AuthType Basic -->设置身份验证 Request valia-user -->设置可访问此目录的用户
<File ~"^\.ht"> -->设置.ht*文件的访问权限
Order allow ,deny
Deny from all
</Files> TypesConfig /etc/mime.types -->设置各种文件类型的关联的位置
DefaultType text/plain -->当无法识别文件类型时,则当成文本处理
<Ifmodule mod_mime_magic.c> -->此模块可让服务器根据文件的内容来判断文件类型
MIMEMagicFile conf/magic
</IfModule>
HostnameLookups Off -->记录连接到该网站的主机ip
ErrorLog logs/error_log -->记录浏览器加载网页发生的错误,以及关闭或启动httpd的信息
LogLevel warn -->设置要存入error_log文件中的下消息等级 LogFormat....
LogFormat.....
LogFormat...... -->设置每条记录的格式 CustomLog logs/access_log combined -->访问记录的位置
#CustomLog logs/referer_log referer -->记录浏览者通过本网站所连接出去的网址,使用referer格式
CustomLog logs/agent_log agent -->记录浏览者连接到本网站所使用的网页浏览器版本与种类,使用agent格式
#customLog logs/access_log combined -->若将以上记录都放在一个文件中,则可使用combined格式
ServerSignature On -->server会自动生成网页(错误消息) Alias /icons/ "/var/www/icons" -->为某一目录建立别名
<Directory>
Options Indexes Muitiviews
AllowOverride None
Order allow,deny
alloe from all
</Directory>
Alias /manual/ "/var/www/manual"
<Directory>
Options Indexes Muitiviews
AllowOverride None
Order allow,deny
alloe from all
</Directory>
<IfModule mod_dav_fs.c>
</IfModule> ScriptAlias /cgi-bin/ "/var/www/cgi-bin" -->为script程序的目录设置别名,此目录中的文件会被视为可执行
<IfModule mod_cgid.c>
Scriptsock run/httpd.cgid
</IfModule>
<Dirctory "/var/www/cgi-bin">
AllowOverride None
Options ExecCGI
Order allow ,deny
Allow from all
<Directory> IndexOptions FancyIndexing VersionSort NameWidth=* -->当找不到index.htm等时将会显示列表 AddIcon
..
..
...
...
..
..
..
.
..
... -->定义每种文件类型的小图标
Default /icons/unknow.gif ReadmeName README.htm -->此文件会显示在文件的结尾,表示需要自己建立README.html
HeaderName README.htm -->此文件会显示在文件的开头,表示需要自己建立README.html
IndexIgnore .??~#$#^%& -->遇到这种文件不要列出来
AddEncoding x-compress Z
AddEncoding x-gzip gz tgz -->当遇到此扩展名,自动压缩 #以下对语言,字符等的配置
addLanguage da.dk
...
...
...
...
...
...
...
...
... AddHandler cgi-script.cgi -->设置遇到某些有扩展名的文件处理,遇到.cgi,当作cgi-script处理
..
..
.. #ErrorDocument 500 "the server made a boo boo"
#...
#... Alias /error/ "/var/www/error" #处理错误,缓存and so on.. #虚拟主机配置
#333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333
#virtual host
<VrualHost *>
ServerSignature email
DirectoryIndex index.htm index.html default.asp index.asp
LogLevel warn
HostNameLookups off
</VirtualHost> <Directory "/">
Options FollowSymLinks
AllowOverride None
</Directory> <Directory "/var/www/html">
Options FollowSymLinks
AllowOverride None
allow from from all
order allow ,deny
</Directory> <Directory "/var/www/icons">
Options FollowSymLinks
AllowOverride None
allow from from all
order allow ,deny
</Directory> <Directory "/var/www/cgi-bin">
Options FollowSymLinks
AllowOverride None
allow from from all
order allow ,deny
</Directory> #一个例子
<VirtualHost 192.126.2.5>
ServerName www.linxe.com
ServerAdmin [email protected]
DocumentRoot /Group/myimages/html
Errorlog logs/groups/logs/error_log
<VirtualHost> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For example
1>配置虚拟主机
基于ip地址的虚拟主机
1:ip地址相同,port不同
[]#cd /etc/httpd
[]#mkdir vipname.d
[]#mkdir /var/www/vipname_sameip1
[]#mkdir /var/www/vipname_sameip2
[/etc/httpd/vipname.d]#vim vipname_sameip.conf
Listen 81
Listen 8100 <VirtualHost 192.168.8.2:81>
Serversignature email
DocumentRoot /var/www/vipname_sameip1
DirectoryIndex index.html
LogLevel warn
HostNameLookups off
</VirtualHost> <VirtualHost 192.168.8.2:8100>
Serversignature email
DocumentRoot /var/www/vipname_sameip2
DirectoryIndex index.html
LogLevel warn
HostNameLookups off
</VirtualHost>
[]#vim /etc/htppd/httpd.conf
#结尾加上以下语句
include /vipname.d/*.conf
[]#service httpd restart
end
2:ip地址不同,port相同
只有一块物理网卡
eth0通过命令变为eth0:0和eht0:1同时捕获多个ip
ip1:192.168.01,IP2:192.168.0.2 #建立目录
[]#mkdir -p /var/www/vipname_sameport1
[]#mkdir -p /var/www/vipname_sameport2 #模块设定
[/etc/httpd/vname.d]#vim vipname_sameport.conf <VirtualHost 192.168.0.1:81>
Serversignature email
DocumentRoot /var/www/vipname_sameiport1
DirectoryIndex index.html
LogLevel warn
HostNameLookups off
</VirtualHost> <VirtualHost 192.168.0.2:81>
Serversignature email
DocumentRoot /var/www/vipname_sameiport2
DirectoryIndex index.html
LogLevel warn
HostNameLookups off
</VirtualHost> #写入配置模块
[]#vim /etc/httpd/httpd.conf
include /vipname.d/*.conf
[]#service httpd restart
2>基于名称的虚拟主机配置
3>动态虚拟寻主机的配置
4>组织和管理个人站定
[]#cd /home/ank
[]#mkdir public_html
[]#chmod 711 public_html
[]#chown ank public_html
[]#chgrp ank public_html
[]#vim /etc/httpd/conf/htttpd.conf
<?很郁闷,我这样做了可就时不会来,不知道哪里错了>
5>配置web目录
accessFilneName .htaccess
<Directory "/var/www/html"> -->设置默认路径 <Directory /var/www/html/ank>
Order allow,deny
allow from all
</Directory>
6>访问控制
order deny,allow -->order用来指定先后顺序
Allow from all
7>设置url路径名 8>验证web用户(略)
相关阅读 更多 +