「Apache HTTP Server」是開源軟件項目的傑出表明,基於標準的HTTP網絡協議提供網頁瀏覽服務,在Web服務器領域中長期保持着超過半數的份額。Apache服務器能夠運行在Linux,UNIX,Windows等多種操做平臺中html
Centos6:httpd2.2java
Centos7:httpd2.4web
/etc/httpd/conf/httpd.conf apache
/etc/httpd/conf.d/*.conf編程
/etc/rc.d/init.d/httpd vim
配置文件:/etc/sysconfig/httpd瀏覽器
/usr/sbin/httpd
/usr/sbin/httpd.event
/usr/sbin/httpd.worker 安全
/var/log/httpd 服務器
/var/log/httpd/access_log 訪問日誌 網絡
/var/log/httpd/error_log 錯誤日誌
/var/www/html
/usr/lib64/httpd/modules
[root@Server ~]# grep "Section" /etc/httpd/conf/httpd.conf ### Section 1: Global Environment ### Section 2: 'Main' server configuration ### Section 3: Virtual Hosts
directive value
directive: 不區分字符大小寫
value:爲路徑時,取決於文件系統
1 [root@Server ~]# yum -y install httpd httpd-manual
[root@Server ~]# vim /etc/httpd/conf/httpd.conf #ServerName www.example.com:80 ServerName localhost:80
[root@Server ~]# service httpd start
正在啓動 httpd:
[root@Server ~]# service iptables stop [root@Server ~]# setenforce 0
[root@Server ~]# service httpd restart
中止 httpd: [肯定]
正在啓動 httpd: [肯定]
ServerRoot "/etc/httpd" //apache軟件安裝的位置。其它指定的目錄若是沒有指定絕對路徑,則目錄是相對於該目錄。 PidFile run/httpd.pid //第一個httpd進程(全部其餘進程的父進程)的進程號文件位置。
Timeout 60 //設置鏈接超時,參數timeout,當鏈接超過必定的空閒時間,就會自動斷開
KeepAlive On //設置keepalive,提升網絡效率,默認是關閉的
MaxKeepAliveRequests 100 //設置keepaliverequest,設置爲0 的時候沒有限制,不過最好仍是用默認值,或者本身根據狀況來改變
Listen 80 //服務器監聽的端口號。 ServerName localhost:80 //主站點名稱(網站的主機名)。 ServerAdmin admin@clusting.com //管理員的郵件地址。 DocumentRoot "/var/www/htdocs" //主站點的網頁存儲位置。
DirectoryIndex index.html index.html.var //設置網站主頁文件
AddDefaultCharset UTF-8 //設置字符集,參數AddDefaultCharset,建議最好設置utf-8,這是通用的。
<Directory "/var/www/htdocs"> Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory>
在上面這段目錄屬性配置中,主要有下面的選項:
ExecCGI: 在該目錄下容許執行CGI腳本。
FollowSymLinks: 在該目錄下容許文件系統使用符號鏈接。
Indexes: 當用戶訪問該目錄時,若是用戶找不到DirectoryIndex指定的主頁文件(例如index.html),則返回該目錄下的文件列表給用 戶。
SymLinksIfOwnerMatch: 當使用符號鏈接時,只有當符號鏈接的文件擁有者與實際文件的擁有者相同時才能夠訪問。
None: 當AllowOverride被設置爲None時。不搜索該目錄下的.htaccess文件(能夠減少服務器開銷)。
All: 在.htaccess文件中可使用全部的指令。
Allow:容許訪問的主機列表(可用域名或子網,例如:Allow from 192.168.0.0/16)。
Deny:拒絕訪問的主機列表。
apache2主要的優點就是對多處理器的支持更好,在編譯時同過使用–with-mpm選項來決定apache2的工做模式。若是知道當前的apache2使用什麼工做機制,能夠經過httpd -l命令列出apache的全部模塊,就能夠知道其工做方式:
prefork:若是httpd -l列出prefork.c,則須要對下面的段進行配置:
<IfModule prefork.c> StartServers 5 #啓動apache時啓動的httpd進程個數。 MinSpareServers 5 #服務器保持的最小空閒進程數。 MaxSpareServers 10 #服務器保持的最大空閒進程數。 MaxClients 150 #最大併發鏈接數。 MaxRequestsPerChild 1000 #每一個子進程被請求服務多少次後被kill掉。0表示不限制,推薦設置爲1000。 </IfModule>