web服務之httpd2.2及2.4配置詳解02

來源:互聯網
上載者:User

標籤:httpd2.4配置   httpd2.4虛擬機器主機   httpd2.4存取控制   httpd特性   

本文繼續淺談httpd2.2相關配置,httpd-2.4的變化及相關配置,LAMP相關知識


http2.2 相關配置

1. httpd status頁面的展示

    查看status_module模組是否裝載

[[email protected] tmp]# httpd -M|grep status status_module (shared)Syntax OK


全域設定檔開啟如下配置即可,也可以在virtualhost中配置

<Location /server-status>    SetHandler server-status    Order allow,deny    Allow from 172.16.0.0/16 #status頁面顯示了web服務的運行資訊,建議設定存取控制</Location>


2. httpd服務進程許可權管理

    user / group

    指定以哪個使用者身份運行httpd服務進程   

     User apache     Group apache


3. 使用mod_deflate模組壓縮頁面最佳化傳輸速度

    配置如下:將下面配置放到全域設定檔httpd.conf

# mod_deflate configurationSetOutputFilter DEFLATE# Restrict compression to these MIME typesAddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/htmlAddOutputFilterByType DEFLATE application/xhtml+xmlAddOutputFilterByType DEFLATE text/xmlAddOutputFilterByType DEFLATE application/xmlAddOutputFilterByType DEFLATE application/x-javascriptAddOutputFilterByType DEFLATE text/javascriptAddOutputFilterByType DEFLATE text/css # Level of compression (Highest 9 - Lowest 1)DeflateCompressionLevel 9 # Netscape 4.x has some problems.BrowserMatch ^Mozilla/4  gzip-only-text/html # Netscape 4.06-4.08 have some more problemsBrowserMatch  ^Mozilla/4\.0[678]  no-gzip # MSIE masquerades as Netscape, but it is fineBrowserMatch \bMSI[E]  !no-gzip !gzip-only-text/html

    適用情境:

(1) 節約頻寬,額外消耗CPU;同時,可能有些較老瀏覽器不支援;

(2) 壓縮適於壓縮的資源,例如檔案檔案;

  

4. httpd 壓力測試工具

    ab、webbench、http_load、loadrunner、等。

    這裡介紹一下ab(ApacheBench)

    ab [options] url

        -n:總請求數

        -c:類比的並發數

        -k:以持久串連模式 測試

    # ab -c 10 -n 1000 http://www.linux.com/index.html

    

 

httpd-2.4基本應用 

1.httpd-2.4新特性

    (1) MPM支援運行為DSO機制;以模組形式按需載入;

    (2) event MPM生產環境可用;

    (3) 非同步讀寫機制;

    (4) 支援每模組及每目錄的單獨記錄層級定義;

    (5) 每請求相關的專用配置;

    (6) 增強版的運算式分析式;

    (7) 毫秒級持久串連時間長度定義;

    (8) 基於FQDN的虛擬機器主機也不再需要NameVirutalHost指令;

    (9) 新指令,AllowOverrideList;

    (10) 支援使用者自訂變數;

    (11) 更低的記憶體消耗;

2.httpd-2.4新模組

    (1)mod_proxy_fcgi    (2)mod_proxy_scgi    (3)mod_remoteip


3.安裝httpd-2.4

    centos6安裝httpd-2.4

        依賴與apr-1.4+,apr-util-1.4+

            apr:apache portable runtime(可移植運行時程式)

         centos6 要先編譯安裝apr-1.4+ 和 apr-util-1.4+,然後在編譯安裝httpd-2.4 

    centos7安裝httpd-2.4

        centos7 base源中內建了httpd-2.4,直接yum安裝即可

        yum install httpd


4.centos7中httpd-2.4的配置

4.1 程式運行環境

    設定檔:

  /etc/httpd/conf/httpd.conf        /etc/httpd/conf.d/*.conf        模組相關的設定檔:/etc/httpd/conf.modules.d/*.conf

    systemd unit file:

 /usr/lib/systemd/system/httpd.service

    主程式檔案:

  /usr/sbin/httpd        httpd-2.4 支援MPM的動態切換

    記錄檔:

    /var/log/httpd:            access_log:訪問日誌            error_log:錯誤記錄檔

    網站目錄:

     /var/www/html

    模組檔案路徑:

 /usr/lib64/httpd/modules

    服務控制:

    systemctl  enable|disable  httpd.service    systemctl  {start|stop|restart|status}  httpd.service


4.2 切換使用MPM

    編輯配置/etc/httpd/conf.modules.d/00-mpm.conf檔案

    啟用要使用的MPM相關的LoadModule指令,然後重啟服務即可


4.3 基於IP的存取控制

    httpd2.4中,使用Require指令進行存取控制,不在支援2.2中的allow,deny.

    允許所有主機訪問:Require all granted

    拒絕所有主機訪問:Require all denied

    

    控制特定的ip訪問:

        Require ip IPADDR: 授權指定來源的主機訪問

        Require not ip IPADDR: 拒絕


    控制特定主機訪問:

        Require host HOSTNAME: 授權指定來源的主機訪問

        Require  not  host  HOSTNAME:拒絕


    配置模組:在Directory標籤中

<RequireAll>

    Require all granted

    Require not ip 172.16.100.1

</RequireAll>

   

4.4 基於網域名稱的虛擬機器主機配置

    httpd-2.4中基於FQDN的虛擬機器主機也不再需要NameVirutalHost指令;

    模版樣本:

<VirtualHost *:80>    ServerName www1.linux.com    DocumentRoot "/web/vhosts/www1"    CustomLog "/var/log/httpd/www1/www1.access_log" combined    ErrorLog "/var/log/httpd/www1/www1.error_log"    <Directory "/web/vhosts/www1">        Options None        AllowOverride None        <RequireAll>            Require all granted            Require not ip 10.0.0.0/24        </RequireAll>    </Directory></VirtualHost>

    注意:任意網站目錄下的頁面只有顯示授權才能被訪問


4.5 持久串連

    httpd2.4中支援毫秒級的持久串連

    KeepAliveTimeout  #ms

    

    毫秒級持久串連時間長度定義,檔案自行建立

      /etc/httpd/conf.d/ka.conf            KeepAlive On            KeepAliveTimeout  500ms            MaxKeepAliveRequests 100


LAMP相關知識

1. web資源類型        

    靜態資源:原始形式與相應結果一致

    動態資源:原始形式通常為程式檔案,需要運行後將結果響應給用戶端。


2. CGI:Common Gateway Interface

   通用閘道介面(Common Gateway Interface/CGI)是一種重要的互連網技術,可以讓一個用戶端,從網頁瀏覽器向執行在網路伺服器上的程式請求資料。CGI描述了伺服器和請求處理常式之間傳輸資料的一種標準。


3. LAMP的實現方式

    方案1:httpd(prefork)+libphp5.so+mysql

    方案2:httpd(event)+libphp5-zts.so+mysql

    方案3:httpd+fpm(php)+mysql


4. centos6上簡單實現LAMP

    採用yum安裝的方式:

    # yum install httpd php php-mysql mysql-server    # service mysqld start    # service httpd start

    

5.centos7上簡單實現LAMP

    採用yum安裝的方式:

    # yum install httpd php php-mysql mariadb-server    # systemctl start mariadb.service httpd.service

    php設定檔:

        /etc/php.ini、/etc/php.d/*.ini


    測試httpd與php的串連性:

    <?php         phpinfo();    ?>

    

    測試php與mysql的串連性

    <?php        $conn = mysql_connect(‘172.16.100.1‘,‘testuser‘,‘testpass‘);        if($conn)            echo "OK";        else            echo "Failure";    ?>



感謝MageEdu

本文出自 “Hello,Linux” 部落格,轉載請與作者聯絡!

web服務之httpd2.2及2.4配置詳解02

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.