Apache 相對於nginx的配置對比起來相當復雜啦,朋友之前的系統使用的是Apache需要增加一個虛擬主機,主要配置從Apache轉發Tomcat。
首先需要拆解下步驟:
- Apache 支持Https;
- Apache 代理轉發;
- Apache https 代理轉發Tomcat http;
1.Apache 支持 https
( 1 )打開 apache 安裝目錄下 conf 目錄中的 httpd.conf 文件,找到以下內容並去掉“#”:
#LoadModule ssl_module modules/mod_ssl.so (如果找不到請確認是否編譯過 openssl 插件)
#Include conf/extra/httpd-ssl.conf
如果mod_ssl.so 文件不存在的時候
( 2 ) 打開 apache 安裝目錄下 conf/extra/httpd-ssl.conf 文件 (也可能是conf.d/ssl.conf,與操作系統及安裝方式有關),在配置文件中查找以下配置語句:
# 添加 SSL 協議支持協議,去掉不安全的協議
SSLProtocol all -SSLv2 -SSLv3
# 修改加密套件如下
SSLCipherSuite HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM
SSLHonorCipherOrder on
# 證書公鑰配置
SSLCertificateFile cert/public.pem
# 證書私鑰配置
SSLCertificateKeyFile cert/214105172620338.key
# 證書鏈配置,如果該屬性開頭有 '#'字符,請刪除掉
SSLCertificateChainFile cert/chain.pem
( 3 ) 重啟 Apache。
2.Apache 代理轉發
(1)在http.conf 配置文件中開啟代理模塊
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
(2)配置反向代理
<VirtualHost _default_:443> DocumentRoot "/usr/local/httpd/apache2/htdocs" ServerName xxx.deercity.cn ServerAdmin xxx.deercity.cn ErrorLog "/usr/local/httpd/apache2/logs/error_log" TransferLog "/usr/local/httpd/apache2/logs/access_log" ProxyPass / http://127.0.0.1:9080/ ProxyPassReverse / http://127.0.0.1:9080/ </VirtualHost>
3. 配置Apache Https 轉發Tomcat Http
(1) 配置Tomcat server.xml 文件,添加proxyPort和scheme如下圖:
<Connector port="9080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" proxyPort="443" scheme="https" />
4.重啟啟動Tomcat和Apache 實現https 轉發Tomcat http
完全的APache配置文件
Listen 443 AddType application/x-x509-ca-cert .crt AddType application/x-pkcs7-crl .crl SSLPassPhraseDialog builtin SSLSessionCache "shmcb:/usr/local/httpd/apache2/logs/ssl_scache(512000)" SSLSessionCacheTimeout 300 SSLMutex "file:/usr/local/httpd/apache2/logs/ssl_mutex" ProxyPreserveHost On <VirtualHost _default_:443> DocumentRoot "/usr/local/httpd/apache2/htdocs" ServerName xxx.deercity.cn ServerAdmin xxx.deercity.cn ErrorLog "/usr/local/httpd/apache2/logs/error_log" TransferLog "/usr/local/httpd/apache2/logs/access_log" ProxyPass / http://127.0.0.1:9080/ ProxyPassReverse / http://127.0.0.1:9080/ SSLEngine on SSLProxyEngine on SSLProtocol all -SSLv2 SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5 SSLHonorCipherOrder on SSLCertificateFile "/usr/local/httpd/apache2/conf/cert/public.pem" SSLCertificateKeyFile "/usr/local/httpd/apache2/conf/cert/214194390240886.key" SSLCertificateChainFile "/usr/local/httpd/apache2/conf/cert/chain.pem" <FilesMatch "\.(cgi|shtml|phtml|php)$"> SSLOptions +StdEnvVars </FilesMatch> <Directory "/usr/local/httpd/apache2/cgi-bin"> SSLOptions +StdEnvVars </Directory> BrowserMatch "MSIE [2-5]" \ nokeepalive ssl-unclean-shutdown \ downgrade-1.0 force-response-1.0 CustomLog "/usr/local/httpd/apache2/logs/ssl_request_log" \ "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b" </VirtualHost>