標籤:apache linux https cgi
Apache安裝及配置
1.1 下載軟體
1、Apr :(wget http://mirrors.hust.edu.cn/apache//apr/apr-1.5.1.tar.gz)
2、Apr-util :(wget http://mirrors.hust.edu.cn/apache//apr/apr-util-1.5.4.tar.gz)
3、Pcre :(wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.35.tar.bz2)
4、Openssl :(wget http://www.openssl.org/source/openssl-1.0.2.tar.gz)
5、Apache :(wget http://www.eu.apache.org/dist/httpd/httpd-2.4.12.tar.gz)
1.2 安裝Apache
請按照下面的順序安裝:
1.2.1安裝apr
[[email protected] test]# tar -zxf apr-1.5.1.tar.gz
[[email protected] test]# cd apr-1.5.1
[[email protected] apr-1.5.1]# ./configure --prefix=/usr/local/apr
[[email protected] apr-1.5.1]# make && make install
1.2.2安裝apr-util
[[email protected] test]# tar -zxf apr-util-1.5.4.tar.gz
[[email protected] test]# cd apr-util-1.5.4
[[email protected] apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util -with- apr=/usr/local/apr/bin/apr-1-config
[[email protected] apr-util-1.5.4]# make && make install
1.2.3 安裝pcre
[[email protected] test]#tar -xjf pcre-8.35.tar.bz2
[[email protected] test]#cd pcre-8.35
[[email protected] pcre-8.35]#./configure --prefix=/usr/local/pcre
[[email protected] pcre-8.35]#make && make install
1.2.4 安裝openssl
[[email protected] test]#tar -zxf openssl-1.0.2.tar.gz
[[email protected] test]# cd openssl-1.0.2
[[email protected] openssl-1.0.2]#./config --prefix=${destination_dir} -fPIC no-gost no-shared no-zlib
[[email protected] openssl-1.0.2]#make depend ; make install
1.2.5 安裝apache
[[email protected] test]Tar -zcf httpd-2.4.12.tar.gz
[[email protected] test]Cd httpd-2.4.12
[[email protected] httpd-2.4.12]./configure --prefix=/opt/wacos/tools/apache --enable-so --enable-ssl --with-ssl=/usr/local/ssl --enable-mods-shared=all --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre
[[email protected] httpd-2.4.12]#make ; make install
1.3 配置Apache,讓apache支援https和fcgi
1.3.1 對https的支援
原理:一般一個http請求預設是80連接埠,一個https請求預設是443連接埠,這就要對apache配置虛擬機器主機以支援同網域名稱多連接埠。在apache安裝目錄的conf/extra檔案中有一個httpd-ssl.conf檔案,裡面是這些內容。
Listen 443
<VirtualHost _default_:443>
DocumentRoot "/opt/wacos/tools/apache/htdocs"
ServerName www.example.com:443
ErrorLog "/opt/wacos/tools/apache/logs/error_log"
TransferLog "/opt/wacos/tools/apache/logs/access_log"
</VirtualHost >
https協議是http協議裡面加了一層ssl加密過程。伺服器端需要一個認證檔案和一個密鑰檔案。下面是產生認證和密鑰的過程:
1、openssl genrsa -out server.key 2048
運行openssl命令,產生2048位長的私密金鑰server.key
2、openssl req -new -key server.key -out server.csr
輸入命令以後,需要填寫如下內容:
Country Name(國家:中國填寫CN)
State or Province Name(地區或是省份:CHONGQING)
Locality Name(地區局部名字:CHONGQING)
Organization Name(機構名稱:填寫公司名)
Organizational Unit Name(組織單位名稱:部門名稱)
Common Name(網站網域名稱)
Email Address(郵箱地址)
A challenge password(輸入一個密碼)
An optional company name(一個可選的公司名稱)
輸入完這些內容,就會在目前的目錄產生server.csr檔案
3、openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
使用上面的密鑰和CSR對認證進行簽名
到此為止,就有了伺服器私人密鑰(server.key)和伺服器憑證(server.crt)。
接下來把密鑰和憑證路徑添加到上面配置的虛擬機器主機裡面:
SSLCertificateFile "/opt/wacos/tools/apache/conf/server.crt"
SSLCertificateKeyFile "/opt/wacos/tools/apache/conf/server.key"
把https的開關開啟
SSLEngine on
這樣就完成了對httpd-ssl.conf檔案的配置。
在conf目錄下有一個httpd.conf檔案,開啟,
找到#Include conf/extra/httpd-ssl.conf一行,把#去掉。
找到#LoadModule ssl_module modules/mod_ssl.so一行,把#去掉。
重啟apache伺服器,在瀏覽器上進行https測試。
1.3.2 對fcgi的支援
Fcgi是一個進程,需要在apache啟動的時候同時載入進程。Apache要支援fcgi,需要載入mod_fcgid.so模組。
安裝mod_fcgid.so模組:
[[email protected] test](wget http://www.apache.org/dist/httpd/mod_fcgid/mod_fcgid-2.3.9.tar.gz)
[[email protected] test]tar -zxf mod_fcgid-2.3.9.tar.gz
[[email protected] test]cd mod_fcgid-2.3.9
[[email protected] test]APXS=/opt/wacos/tools/apache/bin/apxs ./configure.apxs
[[email protected] test]make && make install
安裝成功後,會在module目錄中產生mod_fcgid.so檔案
開啟httpd.conf檔案,找到#LoadModule fcgid_module modules/mod_fcgid.so一行,去掉#號。添加以下代碼:
<IfModule fcgid_module>
ScriptAlias /fcgi-bin/ "/opt/wacos/tools/apache/fcgi-bin/"
<Directory "/opt/wacos/tools/apache/fcgi-bin">
SetHandler fcgid-script
Options +ExecCGI
Order allow,deny
Allow from all
</Directory>
</IfModule>
至此,對fcgi支援的配置已經完成。
寫一個cgi程式放在fcgi-bin目錄中,重啟apache測試。
安裝配置Apache支援https和fcgi