環(huán)境:
RedHat 9.0
說明:
使用$ 開頭的是普通用戶身份執(zhí)行的命令
使用# 開頭的是root帳號執(zhí)行的命令
第一步:安裝apache
下載apache2: http://httpd.apache.org/download.cgi
我需要mod_ssl的支持,和apache1不同的是,mod_ssl不在是單獨的模塊,而是放在apache發(fā)行包里面了,默認是不啟用的,config的時候選擇上就可以了。
我使用DSO方式編譯安裝apache,同時將全部模塊都編譯好,以方便后來可能的需要。只要編輯httpd.conf,在里面去掉不想要的模塊(注釋或者刪除對應模塊的LoadModule行),就可以定制自己的apache咯。
$ tar zxvf httpd-2.0.50.tar.gz
$ ./configure --prefix=/usr/local/apache2 --enable-so --enable-ssl=shared --enable-mods-shared=all --with-ssl=/usr/local/ssl
$ make
$ su
# make install
Apache有兩種使用模塊的方法,其一是永久性包含進核心;
如果操作系統支持動態(tài)共享對象(DSO),而且能為autoconf所檢測,則模塊還可以被動態(tài)編譯。
DSO模塊的存儲是獨立與核心的,可以被核心使用由mod_so模塊提供的運行時刻配置指令包含或排除。
如果編譯中包含有任何動態(tài)模塊,則mod_so模塊會被自動包含進核心。如果希望核心能夠裝載DSO,而不實際編譯任何動態(tài)模塊,需要明確指定--enable-so。
(http://kajaa.bbs.us/ApacheManual/install.html)
第一次按照上述方法編譯的apache,啟動的時候會報錯:
# cd /usr/local/apache2
# ./bin/apachectl startssl
Syntax error on line 251 of /usr/local/apache/conf/httpd.conf:
Cannot load /usr/local/apache/modules/mod_ssl.so into server: /usr/local/apache/modules/mod_ssl.so: undefined symbol: X509_free
原因是什么呢?看 http://www.smartframeworks.com/qt-apache-ssl.html
因為按照下面的方法(參看:Apache2 + mod_ssl + php5 完全安裝實錄(2))安裝的openssl默認是沒有編譯成動態(tài)鏈接庫的,因為其文檔說openssl的動態(tài)鏈接庫還不成熟,可以使用 ./config shared 編譯帶動態(tài)鏈接庫的openssl,但是還處于試驗階段。
解決這個問題的辦法是:將mod_ssl靜態(tài)的編譯到apache里面。
請使用下面的方法重新來過:)
$ ./configure --prefix=/usr/local/apache2 --enable-so --enable-ssl=static --with-ssl=/usr/local/ssl --enable-mods-shared=all
$ make
$ su
# make install
這次啟動apache的時候又發(fā)現一個錯誤:
# cd /usr/local/apache2
# ./bin/apachectl startssl
Syntax error on line 108 of /usr/local/apache2/conf/ssl.conf:
SSLCertificateFile: file '/usr/local/apache2/conf/ssl.crt/server.crt' does not exist or is empty
這又是什么原因呢?因為我們沒有配置ssl,需要生成ssl需要的證書。
以前使用apache1+mod_ssl的時候,make之后有一個這樣的步驟
$ make certificate
可以用來生成ssl所用到的證書。
現在沒有這個工具了,只能自己動手生成了,對證書不熟悉的人,有一個工具可以使用:http://www.openssl.org/contrib/ssl.ca-0.1.tar.gz
# cd /usr/local/apache2/conf
# tar zxvf ssl.ca-0.1.tar.gz
# cd ssl.ca-0.1
# ./new-root-ca.sh (生成根證書)
No Root CA key round. Generating one
Generating RSA private key, 1024 bit long modulus
...........................++++++
....++++++
e is 65537 (0x10001)
Enter pass phrase for ca.key: (輸入一個密碼)
Verifying - Enter pass phrase for ca.key: (再輸入一次密碼)
......
Self-sign the root CA... (簽署根證書)
Enter pass phrase for ca.key: (輸入剛剛設置的密碼)
........
........ (下面開始簽署)
Country Name (2 letter code) [MY]:CN
State or Province Name (full name) [Perak]:JiangSu
Locality Name (eg, city) [Sitiawan]:NanJing
Organization Name (eg, company) [My Directory Sdn Bhd]:Wiscom System Co.,Ltd
Organizational Unit Name (eg, section) [Certification Services Division]:ACSTAR
Common Name (eg, MD Root CA) []:WISCOM CA
Email Address []:acmail@wiscom.com.cn
這樣就生成了ca.key和ca.crt兩個文件,下面還要為我們的服務器生成一個證書:
# ./new-server-cert.sh server (這個證書的名字是server)
......
......
Country Name (2 letter code) [MY]:CN
State or Province Name (full name) [Perak]:JiangSu
Locality Name (eg, city) [Sitiawan]:NanJing
Organization Name (eg, company) [My Directory Sdn Bhd]:Wiscom System Co.,Ltd
Organizational Unit Name (eg, section) [Secure Web Server]:ACSTAR
Common Name (eg, www.domain.com) []:acmail.wiscom.com.cn
Email Address []:acmail@wiscom.com.cn
這樣就生成了server.csr和server.key這兩個文件。
還需要簽署一下才能使用的:
# ./sign-server-cert.sh server
CA signing: server.csr -> server.crt:
Using configuration from ca.config
Enter pass phrase for ./ca.key: (輸入上面設置的根證書密碼)
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName :PRINTABLE:'CN'
stateOrProvinceName :PRINTABLE:'JiangSu'
localityName :PRINTABLE:'NanJing'
organizationName :PRINTABLE:'Wiscom System Co.,Ltd'
organizationalUnitName:PRINTABLE:'ACSTAR'
commonName :PRINTABLE:'acmail.wiscom.com.cn'
emailAddress :IA5STRING:'acmail@wiscom.com.cn'
Certificate is to be certified until Jul 16 12:55:34 2005 GMT (365 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
CA verifying: server.crt <-> CA cert
server.crt: OK
(如果這里出現錯誤,最好重新來過,刪除ssl.ca-0.1這個目錄,從解壓縮處重新開始。)
下面要按照ssl.conf里面的設置,將證書放在適當的位置。
# chmod 400 server.key
# cd ..
# mkdir ssl.key
# mv ssl.ca-0.1/server.key ssl.key
# mkdir ssl.crt
# mv ssl.ca-0.1/server.crt ssl.crt
然后就可以啟動啦!
# cd /usr/local/apache2
# ./bin/apachectl startssl
對于這個提示:
httpd: Could not determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
只需要編輯httpd.conf,找到ServerName xxxx這一行,去掉前面的注釋即可。