Linux學習筆記14–架設Apache http伺服器

來源:互聯網
上載者:User
圖形環境下單擊“Applications → System Settings → Add/Remove Application”功能表項目,
在Server下找的"Web Server"選項,並選中,然後點Update按鈕,按提示安裝。
1-2:
圖1:

圖2:

安裝前需要把載入Linux系統安裝光碟片。
3:
圖3:

安裝好Apache伺服器,可以在命令視窗輸入命令來啟動Apache服務:
[root@CentOS4 ~]# /etc/rc.d/init.d/httpd start
Starting httpd: [  OK  ]
[root@CentOS4 ~]#

啟動之後,初步對HTTP服務進行簡單測試,4:
圖4:

關閉Apache服務:
[root@CentOS4 ~]# /etc/rc.d/init.d/httpd stop
Stopping httpd: [  OK  ]

重新啟動Apache服務:
[root@CentOS4 ~]# /etc/rc.d/init.d/httpd restart
Stopping httpd: [  OK  ]
Starting httpd: [  OK  ]

接下來就簡單瞭解配置HTTP(Apache)伺服器:
設定檔httpd.conf位於/etc/httpd/conf目錄下.

[root@CentOS4 ~]# cat /etc/httpd/conf/httpd.conf
#
# Based upon the NCSA server configuration files originally by Rob McCool.
#
# This is the main Apache server configuration file.  It contains the
# configuration directives that give the server its instructions.
# See <URL:http://httpd.apache.org/docs-2.0/> for detailed information about
# the directives.
#
# Do NOT simply read the instructions in here without understanding
# what they do.  They're here only as hints or reminders.  If you are unsure
# consult the online docs. You have been warned.  
#
# The configuration directives are grouped into three basic sections:
#  1. Directives that control the operation of the Apache server process as a
#     whole (the 'global environment').
#  2. Directives that define the parameters of the 'main' or 'default' server,
#     which responds to requests that aren't handled by a virtual host.
#     These directives also provide default values for the settings
#     of all virtual hosts.
#  3. Settings for virtual hosts, which allow Web requests to be sent to
#     different IP addresses or hostnames and have them handled by the
#     same Apache server process.

... ...

設定檔基本分為三個小節,一個global environment全域環境,一個'main' or 'default' server
主服務/預設伺服器配置,還有一個是Settings for virtual hosts虛擬連接埠配置。

常用配置參數有:
DocumentRoot "/var/www/html"  該參數指定Apache伺服器存放網頁的路徑

圖形介面配置顯示5:
圖5:

MaxClients 118  該參數限制Apache所能提供服務的最高數值,最大可以設定到256。

命令列:
... ...省略部分
# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule prefork.c>
StartServers 8
MinSpareServers 5
MaxSpareServers 20
MaxClients 118
MaxRequestsPerChild 100
</IfModule>
... ...省略部分

圖形介面配置顯示6:
圖6:

Port 80  指定Apache伺服器的監聽連接埠,標準的HTTP伺服器預設連接埠為80。

命令列:
... ...省略部分
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, in addition to the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses (0.0.0.0)
#
#Listen 12.34.56.78:80
Listen *:80
... ...省略部分

圖形介面配置顯示7:
圖7:

ServerName CentOS 設定主機名稱.需要在DNS伺服器註冊該主機名稱才可以使用該名來訪問,不然得指定IP地址。
命令列:
... ...省略部分
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If this is not set to valid DNS name for your host, server-generated
# redirections will not work.  See also the UseCanonicalName directive.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
# You will have to access it by its address anyway, and this will make
# redirections work in a sensible way.
#
ServerName CentOS

... ...省略部分

MaxKeepAliveRequests 100 當使用保持串連(Persistent Connection)功能時,
可以使用本參數決定每次串連所能發出的要求數目的上限.

MaxRequestsPerChild 10  該參數限制每個子進程(Child Process)在結束前所能處理的請求數目,一旦達到該數目,這個子進程就會被中止,以避免長時間佔據Apache(或者Apache伺服器所採用的函數庫),
防止造成記憶體或者其他系統資源的超負荷。

MaxSpareServers 和MinSpareServers 提供Web服務的HTTP守護進程.

配置Apache時,我們可以選擇圖形介面配置
或者通過修改設定檔httpd.conf參數進行配置。

[完]

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.