歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> Linux資訊 >> Linux文化 >> 中小企業服務器配置方案 第三章(1)

中小企業服務器配置方案 第三章(1)

日期:2017/2/27 12:15:08   编辑:Linux文化

1.1 簡介

Apache是世界排名第一的Web服務器,根據著名的Web服務器調查公司Netcraft的調查,世界上百分之五十以上的Web服務器都在使用Apache。

縱觀Apache,它為我們的網絡管理員提供了豐富多彩的功能,包括目錄索引、目錄別名、內容協商、可配置的HTTP錯誤報告、CGI程序的SetUID執行、子進程資源管理、服務器端圖象映射、重寫URL、URL拼寫檢查以及聯機手冊man等。也就是說,如果您在Linux Server上成功安裝配置了Apache之後,您的計算機也將隨著Apache的生效而搖身一變,成為一台名副其實的Web Server,這種變化的確是激動人心的。伴隨著自由軟件發展的強大動力,我們有理由相信Apache的未來是一片光明的。
在Internet時代,外部主頁的發布已經成為樹立公司形象的一個重要手段,而內部主頁也成為公司管理的主要方式。但是,要想實現這些功能,首先應該把我們的Linux Server配置成為一台強大的Web Server。時至今日,全球應用最廣泛的Web服務器軟件就是Apache,本章將詳細介紹如何配置Apache服務器。希望各位同仁能夠通過閱讀本片文章達到理論實踐雙豐收的目的,在很短的時間裡迅速成為一名出色的網絡管理員。


1.2 所需資源

1.2.1 所需包
RedHat6.2 服務器安裝

1.2.2 所需配置文件
/etc/httpd/conf/httpd.conf 系統自帶,管理員配置
/etc/httpd/conf/access.conf 系統自帶,不需要修改
/etc/httpd/conf/srm.conf 系統自帶,不需要修改


1.3 配置方案/etc/httpd/conf/httpd.conf
說明:apache主配置文件
源文件:
ServerType standalone
   #定義WebServer的啟動方式為standalone,以增強其對大量訪問的及時響應性
ServerRoot "/etc/httpd"
   #指定包含httpd服務器文件的目錄
LockFile /var/lock/httpd.lock
PidFile /var/run/httpd.pid
ScoreBoardFile /var/run/httpd.scoreboard
Timeout 300
   #響應超時量,單位為秒
KeepAlive On
   #允許用戶建立永久連接
MaxKeepAliveRequests 100
KeepAliveTimeout 15
MinSpareServers 5
   #要保留的空閒服務器進程的最小值
MaxSpareServers 20
   #要保留的空閒服務器進程的最大值
StartServers 8
   #系統啟動時的守護進程數
MaxClients 150
   #所能提供服務的最大客戶端編號,大於它的部分被放入請求隊列
MaxRequestsPerChild 100
LoadModule vhost_alias_module modules/mod_vhost_alias.so
LoadModule env_module     modules/mod_env.so
LoadModule config_log_module modules/mod_log_config.so
LoadModule agent_log_module  modules/mod_log_agent.so
LoadModule referer_log_module modules/mod_log_referer.so
LoadModule mime_module    modules/mod_mime.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule status_module   modules/mod_status.so
LoadModule info_module    modules/mod_info.so
LoadModule includes_module  modules/mod_include.so
LoadModule autoindex_module  modules/mod_autoindex.so
LoadModule dir_module     modules/mod_dir.so
LoadModule cgi_module     modules/mod_cgi.so
LoadModule asis_module    modules/mod_asis.so
LoadModule imap_module    modules/mod_imap.so
LoadModule action_module   modules/mod_actions.so
LoadModule userdir_module   modules/mod_userdir.so
LoadModule alias_module    modules/mod_alias.so
LoadModule rewrite_module   modules/mod_rewrite.so
LoadModule access_module   modules/mod_access.so
LoadModule auth_module    modules/mod_auth.so
LoadModule anon_auth_module  modules/mod_auth_anon.so
LoadModule db_auth_module   modules/mod_auth_db.so
LoadModule digest_module   modules/mod_digest.so
LoadModule proxy_module    modules/libproxy.so
LoadModule expires_module   modules/mod_expires.so
LoadModule headers_module   modules/mod_headers.so
LoadModule usertrack_module  modules/mod_usertrack.so
LoadModule setenvif_module  modules/mod_setenvif.so
LoadModule perl_module    modules/libperl.so
LoadModule php3_module    modules/libphp3.so
ClearModuleList
AddModule mod_vhost_alias.c
AddModule mod_env.c
AddModule mod_log_config.c
AddModule mod_log_agent.c
AddModule mod_log_referer.c
AddModule mod_mime.c
AddModule mod_negotiation.c
AddModule mod_status.c
AddModule mod_info.c
AddModule mod_include.c
AddModule mod_autoindex.c
AddModule mod_dir.c
AddModule mod_cgi.c
AddModule mod_asis.c
AddModule mod_imap.c
AddModule mod_actions.c
#AddModule mod_speling.c
AddModule mod_userdir.c
AddModule mod_alias.c
AddModule mod_rewrite.c
AddModule mod_access.c
AddModule mod_auth.c
AddModule mod_auth_anon.c
AddModule mod_auth_db.c
AddModule mod_digest.c
AddModule mod_proxy.c
AddModule mod_expires.c
AddModule mod_headers.c
AddModule mod_usertrack.c
AddModule mod_so.c
AddModule mod_setenvif.c
AddModule mod_perl.c
AddModule mod_php3.c
Port 80
   #定義服務器所使用的TCP的端口號
User nobody
Group nobody
   #以上兩行是分配給httpd的新用戶的文件權限,出於安全的考慮把
   它們的權限設置成為最低。
ServerAdmin [email protected]
   #設置Web管理員的郵件地址
ServerName WebOA
   #定義客戶端從服務器讀取數據時返回給客戶端的主機名,其缺省值
   是localhost,第一次安裝Linux的時候經常這裡出錯。
DocumentRoot "/home/weboa/jakarta-tomcat/webapps/weboa"
   #設置所有Apache文檔的根目錄,比如說,用戶對
   http://www.weboa.com.cn/index.html的訪問請求,Apache對它
   的響應是/home/weboa/jakarta-tomcat/webapps/weboa/index.html
<Directory />
   Options FollowSymLinks
   AllowOverride None
</Directory>
<Directory "/home/httpd/html">
   Options Indexes Includes FollowSymLinks
   AllowOverride None
   Order allow,deny
   Allow from all      # 允許所有人訪問
</Directory>
UserDir public_html
DirectoryIndex index.html index.htm index.shtml index.cgi
   #設置多種成功訪問主頁的方式,為的是提高系統的容錯性
AccessFileName .htaccess
<Files ~ "^\.ht">
   Order allow,deny
   Deny from all
</Files>
UseCanonicalName On
TypesConfig /etc/mime.types
DefaultType text/plain
<IfModule mod_mime_magic.c>
   MIMEMagicFile share/magic
</IfModule>
HostnameLookups Off
ErrorLog /usr/httpd/log/error_log
LogLevel warn
   #定義那些錯誤類型被記錄到錯誤日志中
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
   #所有的LogFormat都用來定義日志中的條目
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
CustomLog /usr/httpd/log/access_log common
ServerSignature On
Alias /icons/ "/home/httpd/icons/"
#定義虛擬主機目錄與系統目錄的對應關系
<Directory "/home/httpd/icons">
   Options Indexes MultiViews
   AllowOverride None
   Order allow,deny
   Allow from all
</Directory>
ScriptAlias /cgi-bin/ "/home/httpd/cgi-bin/"
#定義CGI目錄
<Directory "/home/httpd/cgi-bin">
   AllowOverride None
   Options ExecCGI
   Order allow,deny
   Allow from all
</Directory>
IndexOptions FancyIndexing
AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip
AddIconByType (TXT,/icons/text.gif) text/*
AddIconByType (IMG,/icons/image2.gif) image/*
AddIconByType (SND,/icons/sound2.gif) audio/*
AddIconByType (VID,/icons/movie.gif) video/*
AddIcon /icons/binary.gif .bin .exe
AddIcon /icons/binhex.gif .hqx
AddIcon /icons/tar.gif .tar
AddIcon /icons/world2.gif .wrl .wrl.gz .vrml .vrm .iv
AddIcon /icons/compressed.gif .Z .z .tgz .gz .zip
AddIcon /icons/a.gif .ps .ai .eps
AddIcon /icons/layout.gif .html .shtml .htm .pdf
AddIcon /icons/text.gif .txt
AddIcon /icons/c.gif .c
AddIcon /icons/p.gif .pl .py
AddIcon /icons/f.gif .for
AddIcon /icons/dvi.gif .dvi
AddIcon /icons/uuencoded.gif .uu
AddIcon /icons/script.gif .conf .sh .shar .csh .ksh .tcl
AddIcon /icons/tex.gif .tex
AddIcon /icons/bomb.gif core
AddIcon /icons/back.gif ..
AddIcon /icons/hand.right.gif README
AddIcon /icons/folder.gif ^^DIRECTORY^^
AddIcon /icons/blank.gif ^^BLANKICON^^
DefaultIcon /icons/unknown.gif
ReadmeName README
HeaderName HEADER
AddEncoding x-compress Z
AddEncoding x-gzip gz tgz
AddLanguage en .en
AddLanguage fr .fr
AddLanguage de .de
AddLanguage da .da
AddLanguage el .el
AddLanguage it .it
LanguagePriority en fr de
<IfModule mod_php3.c>
   AddType application/x-httpd-php3 .php3
   AddType application/x-httpd-php3-source .phps
</IfModule>
<IfModule mod_php.c>
   AddType application/x-httpd-php .phtml
</IfModule>
AddType application/x-tar .tgz
AddType text/html .shtml
AddHandler server-parsed .shtml
AddHandler imap-file map
BrowserMatch "RealPlayer 4\.0" force-response-1.0
BrowserMatch "Java/1\.0" force-response-1.0
BrowserMatch "JDK/1\.0" force-response-1.0
<IfModule mod_perl.c>
   Alias /perl/ /home/httpd/perl/
<Location /perl>
   SetHandler perl-script
   PerlHandler Apache::Registry
   Options +ExecCGI
</Location>
</IfModule>
Alias /doc/ /usr/doc/
<Location /doc>
   order deny,allow
   deny from all
   allow from localhost
   Options Indexes FollowSymLinks
</Location>
include /etc/httpd/conf/tomcat-apache.conf
Alias /netcard "/home/weboa/jakarta-tomcat/webapps/weboa/net_card"
<Directory "/home/weboa/jakarta-tomcat/webapps/weboa/net_card">
   Options Indexes FollowSymLinks
   allow from all
</Directory>
CacheSize 5
#定義緩存區大小,以KB為單位。可以根據需要和硬盤空間大小進行設置
CacheGcInterval 4
#每隔4小時檢查緩存區,如果已經超過CacheSize就刪除文件
CacheMaxExpire 24
#HTTP文件最多被保持24小時
CacheLastModifiedFactor 0.1
#定義HTTP文件失效期,缺省是0.1 ,意思是說失效期=離最近一次修改的時間X<factor>,比如離最近一次修改的時間是5小時,那麼失效期就是5X0.1=0.5小時
CacheDefaultExpire 1
#這一指令提供一個缺省的時間(小時)來銷毀緩存的文件,這些文件的最後更改時間不詳。CacheMaxExpire 命令不覆蓋這一設置

## 以下是如何對一個目錄進行登陸控制的方法 ##

在/etc/httpd/conf/httpd.conf中添加以下內容:
Alias /weboa/ "/home/weboa/"
<Directory "/home/weboa">
   Options Indexes MultiViews
   AllowOverride authconfig
   Order allow,deny
   Allow from all
</Directory>

在/home/weboa目錄下建立.htaccess文件
   authname "shared files"
   authtype basic
   authuserfile /etc/httpd/conf/passwd
require valid-user

在/etc/httpd/conf目錄下執行命令生成認證文件
htpasswd -c thj thj #創建認證文件和第一個名和密碼
htpasswd weboa weboa #添加其他用戶名和密碼


### 以下是做虛擬主機的實現方法 ###
需要在/etc/httpd/conf/httpd.conf中添加下列內容:
Alias /webadmin/ "/home/weboa/webadmin/html/"
<Directory "/home/weboa/webadmin/html">
   Options Indexes MultiViews
   AllowOverride None
   Order allow,deny
   Allow from all
</Directory>
NameVirtualHost 192.168.0.1 #虛擬域名的DNS服務器
ServerAdmin [email protected] #網管郵件地址
DocumentRoot /home/weboa/webadmin/html/ #服務器頁面目錄
ServerName webadmin.weboa.com.cn #服務器名稱
需要在/var/named/name2ip.conf中添加的內容:
webadmin   IN   A   192.168.0.1


1.4 測試及管理辦法

1.4.1 測試方法
1.每當管理員更改了Apache的設置之後,都應執行 /etc/rc.d/init.d/httpd restart使得更改生效。

1.4.2 管理方法
1. Apache提供大量的日志文件,當Apache出錯的時候,管理員可以根據htppd.conf中的ErrorLog定義的路徑來診斷。具體方法是:
tail -f /var/log/httpd/apache/error_log


1.5 小 結

Web服務是Internet服務器最基本的服務,Linux發行版中包含的Apache軟件是性能優良的Web服務器,也是Internet上最流行的Web服務器,由於它時刻都經歷著無數使用者的測試,所以現行的Apache的默認選項已經是十分適合我們大家的了,你只需要更改其中幾個與當前應用環境緊密相關的選項就可以達到你的目的了。


Copyright © Linux教程網 All Rights Reserved