在/etc/httpd/conf/httpd.conf增加一个转发模块 或者
在/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
原文地址:http://blog.51cto.com/jschu/2062796