In this post I configure a url redirection from
HTTP to
HTTPS and viceversa using the
Apache mod_proxy and the
ProxyPass directive. I assume an environment consisting of two hosts: a
Web Server Apache in front of a
Tomcat Applicaton Server. In the following first example the Apache ProxyPass redirects the HTTP requests to the
SSL port 8443 of the Tomcat Server. In the second example the Apache Web Server is configured to accept SSL connections, so a self-signed certificate is locally installed and the requests are redirected from HTTPS to the non-ssl url of Tomcat Server.
Example 1. From Apache HTTP to Tomcat HTTPS
|
$ yum install mod_ssl
$ vi /etc/httpd/conf.d/virtual_hosts.conf
|
1
2
3
4
5
6
7
8
9
10
11
12
|
NameVirtualHost *:80
<VirtualHost *:80>
ServerName mysite.com
SSLProxyEngine On
RequestHeader set Front-End-Https "On"
CacheDisable *
ProxyPass /myapp https://tomcat-host:8443/myapp
ProxyPassReverse /myapp https://tomcat-host:8443/myapp
RedirectMatch ^/$ http://mysite.com/myapp
</VirtualHost>
|
Example 2. From Apache HTTPS to Tomcat HTTP
|
$ yum install mod_ssl openssl
$ mkdir /etc/httpd/certs
$ cd /etc/httpd/certs
$ openssl genrsa -out mysite.com.key 1024
$ openssl req -new -key mysite.com.key -out mysite.com.csr
$ openssl x509 -req -days 100000 -in mysite.com.csr -signkey mysite.com.key -out mysite.com.crt
|
|
$ vi /etc/httpd/conf.d/ssl.conf
SSLCertificateFile /etc/httpd/certs/mysite.com.crt
SSLCertificateKeyFile /etc/httpd/certs/mysite.com.key
$ vi /etc/httpd/conf.d/virtual_hosts.conf
|
1
2
3
4
5
6
7
8
9
10
11
12
|
NameVirtualHost *:443
<VirtualHost *:443>
ServerName mysite.com
ProxyPass /myapp http://tomcat-host:8080/myapp
ProxyPassReverse /myapp http://tomcat-host:8080/myapp
RedirectMatch ^/$ https://mysite.com/myapp
SSLEngine on
SSLCertificateFile /etc/httpd/certs/mysite.com.crt
SSLCertificateKeyFile /etc/httpd/certs/mysite.com.key
</VirtualHost>
|
Nhận xét
Đăng nhận xét