apache配置轉發到後端的tomcat/jira
在/etc/httpd/conf.d/中新建一個jira.conf的配置文件
<VirtualHost 122.x.x.x:80>
ProxyPreserveHost On
ServerName jira.new.xxx.com
ProxyPass / http://122.x.x.x:8080/
ErrorLog logs/jira_error_log
CustomLog logs/jira_access_log common
</VirtualHost>
apache在http協議基礎上使用ProxyPass轉發URL到tomcat、jira上
ProxyPass模塊主要轉發功能
/etc/httpd/modules/路徑下包含mod_proxy.so 和 mop_proxy_http.so兩個模塊就具備轉發能力
支持https協議加密
yum -y install openssl 安裝openssl提供ssl加密協議,執行命令openssl version查看OpenSSL的版本
mod_ssl.so 該模塊負責將http協議加密成https協議
yum -y install mod_ssl後,/etc/httpd/modules/下會生成mod_ssl.so文件
然後配置/etc/httpd/conf.d/ssl.conf配置文件,配置key密鑰
mod_rewrite.so 該模塊負責實現客戶端瀏覽器訪問http時自動轉成https協議
測試訪問192.168.1.10/examples後,自動轉發到192.168.1.10:80/exaples頁面,http協議轉發跳轉
ProxyPass /examples http://192.168.1.10:8080/examples/
ProxyPassReverse /examples http://192.168.1.10:8080/examples/
客戶端https訪問https://192.168.1.10/docs,自動通過http協議轉發到192.168.1.10:8080/docs
/etc/httpd/conf/httpd.conf配置文件中,添加Include conf.d/*.conf 允許加載其他配置文件
編輯/etc/httpd/conf.d/ssl.conf,使支持https協議
LoadModule ssl_module modules/mod_ssl.so
Listen 443
##
## SSL Virtual Host Context
##
<VirtualHost _default_:443> ##監聽該主機上所有ip的443端口
ErrorLog logs/ssl_error_log ##錯誤日誌路徑
TransferLog logs/ssl_access_log ##訪問日誌路徑
LogLevel warn #日誌登記
SSLEngine on ##開啟ssl加密
SSLProtocol all -SSLv2 ##加密協議
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
SSLCertificateFile /etc/pki/tls/certs/localhost.crt ##證書路徑
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key ##證書密鑰路徑
<Files ~ "\.(cgi|shtml|phtml|php3?)$">
SSLOptions +StdEnvVars
</Files>
<Directory "/var/www/cgi-bin">
SSLOptions +StdEnvVars
</Directory>
SetEnvIf User-Agent ".*MSIE.*" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
CustomLog logs/ssl_request_log \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
# 在https協議中實現ProxyPass轉發URL,實際就是在ssl.conf中添加ProxyPass語句
ProxyPass /test http://192.168.1.10:8080/examples ##實現客戶端訪問https://192.168.1.10/test,自動轉發到http://192.168.1.10/examples
ProxyPassReverse /test http://192.168.1.10:8080/examples
ProxyPass /docs http://192.168.1.10:8080/docs 註意,末尾沒有/符號,http://192.168.1.10:8080/docs/是錯誤的
ProxyPassReverse /docs http://192.168.1.10:8080/docs
實現http自動轉換成https協議
為了讓客戶輸入普通http地址時可以自動跳轉到加密的https頁面,並跳轉到後端tomcat頁面
在/etc/httpd/conf/httpd.conf的站點模塊中,或者conf.d/的指定站點配置文件中配置
RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
RewriteLog /var/log/httpd/rewrite.log
RewriteLogLevel 10
然後重啟httpd服務
轉載:https://www.cnblogs.com/dule/p/5849941.html
http://blog.csdn.net/pierre_/article/details/44980227
apache配置轉發到後端的tomcat/jira