Linux下Apache部署

來源:互聯網
上載者:User

標籤:apache安裝部署

Linux下Apache部署

1.建使用者    

    [root]# groupadd apache

    [root]# useradd apache -g apache

    [root]# passwd apache

    [root]# su - apache


2.下載openssl-1.0.2g.tar.gz到使用者目錄~(/home/apache/)

    

    [apache]#tar -zxvf openssl-1.0.2g.tar.gz

    [apache]#cd openssl-1.0.2g

    [apache]#mkdir /opt/openssl

    [apache]#./config --prefix=/opt/openssl

    [apache]#make && make install

3.下載httpd-2.2.22.tar.gz到使用者目錄~(/home/apache/)

    [apache]#tar -zxvf httpd-2.2.22.tar.gz

    [apache]#cd ../httpd-2.2.22

    [apache]#export LDFLAGS=-ldl //執行下面命令前最好加上這句話,否則可能報錯:            configure: error: ... Error, SSL/TLS libraries were missing or unusable

    [apache]#./configure --prefix=/opt/httpd --enable-so--enable-info--enable-headers --enable-mods-shared=all --enable-ssl=static --with-ssl=/opt/openssl


    指定模組:./configure --prefix=/opt/httpd --enable-so--enable-info--enable-headers --enable-mods-shared="proxy proxy_http proxy_connect" --enable-ssl=static --with-ssl=/opt/openssl --enable-rewrite --enable-speling --enable-forward

    [apache]#make     //編譯apache

    [apache]#make install    //安裝apache

    或者編譯並且安裝apache

    [apache]#make && make install

注意,非root使用者1024以下連接埠不可用,需要修改預設80連接埠為其他可用連接埠

vi /opt/httpd/conf/httpd.conf


4.查看代理模組及安裝:

    ./apachectl -M|grep proxy

    如果沒有任何模組,安裝步驟:(注意:proxy_util.c是基礎模組,必須先安裝。如果出錯,每個命令後都加上)

    cd /home/apache/httpd-2.2.22/modules/proxy

    /opt/httpd/bin/apxs -c -i -a mod_proxy.c proxy_util.c

    /opt/httpd/bin/apxs -c -i -a mod_proxy_http.c

    /opt/httpd/bin/apxs -c -i -a mod_proxy_ftp.c

    /opt/httpd/bin/apxs -c -i -a mod_proxy_connect.c

    /opt/httpd/bin/apxs -c -i -a mod_proxy_balancer.c

    /opt/httpd/bin/apxs -c -i -a mod_proxy_scgi.c

    /opt/httpd/bin/apxs -c -i -a mod_proxy_ajp.c ajp*.c


httpd.conf代理配置,舉例:

#開啟代理服務,用戶端可指定當前IP及連接埠作為代理配置

ProxyRequests On

#代理指向如果是https協議,必須加上該屬性,否則轉寄錯誤

SSLProxyEngine On


ProxyPass/https/https://url/

ProxyPassReverse/https/https://url/


ProxyPass/http/http://url/

ProxyPassReverse/http/http://url/


Listen 8081

<IfModule mod_proxy.c>

<VirtualHost *:8081>

ProxyRequests On

#配置允許訪問的目的地址以及可使用代理的來源地址

<Proxy *>

Order deny,allow

Allow from all

#Allow from IP1 IP2...

</Proxy>

</VirtualHost>

</IfModule>


SSL加虛擬機器設定

Listen 9443

NameVirtualHost *:9443

<VirtualHost *:9443>

#ServerName domain:9443

DocumentRoot htdocs

DirectoryIndex index.htm

#SSLEngine on

#SSLVerifyClient require

SSLVerifyDepth  10

#SSLCertificateFile conf/server.crt

#SSLCertificateKeyFile conf/server.key

#SSLCACertificateFile conf/CFCA_TEST_CS_CA.cer

#SSLCertificateChainFile conf/CFCA_TEST_OCA1.cer

SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL

SSLOptions +StdEnvVars

#ProxyRequests On

#SSLProxyEngine On

#ProxyPass/http/http://url/

#ProxyPassReverse/http/http://url/

</VirtualHost>



如果具有root使用者權限,可把apache加入到自動啟動服務:

[root]#chkconfig --list httpd     //查看httpd服務是否已存在

[root]#chkconfig httpd off    //關閉系統內建了httpd的服務,如果存在httpd服務   

[root]#service httpd status    //查看內建httpd服務狀態

[root]#/opt/httpd/bin/apachectl -k start    //linux啟動apache命令              

[root]#netstat -an|grep :80    //查看linux80連接埠是否開啟

[root]#ps -aux|grep httpd     //linux下查看apache進程

[root]#cd ../..

[root]#cp /opt/httpd/bin/apachectl /etc/rc.d/init.d/apache //拷貝apache啟動指令碼

[root]#vi /etc/rc.d/init.d/apache    // 這裡是編輯apache啟動指令碼

在開頭的#!/bin/sh下面加上(未知作用)

#chkconfig: 2345  85  15

[root]#chkconfig --add apache    //添加apache服務

[root]#chkconfig --list apache    //列出apache服務

[root]#service apache stop    //停止apache服務

[root]#netstat -an|grep :80     //查看linux的80連接埠是否關閉

[root]#ps -aux|grep httpd     //查看是否存在httpd服務,若果之前內建httpd服務啟動的話會導致新添加的apache服務啟動失敗

[root]#service apache start    //啟動apache服務

開啟伺服器ip地址,看是否出現了It works!,如果出現的話,apache已經安裝成功了



root使用者下,Apache的啟動、關閉、重啟

  啟動命令:service httpd start

  關閉命令:service httpd stop

  重啟命令:service httpd restart

  狀態查詢:service httpd status


非root使用者下,Apache的啟動、關閉、重啟

  啟動命令:/opt/httpd/bin/apachectl start

  關閉命令:/opt/httpd/bin/apachectl stop

  重啟命令:/opt/httpd/bin/apachectl restart

  狀態查詢:/opt/httpd/bin/apachectl status



本文出自 “德澤無憂” 部落格,請務必保留此出處http://dezewuyou.blog.51cto.com/2628602/1867158

Linux下Apache部署

聯繫我們

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