Vanellope Vanellope - 11 months ago 128
Apache Configuration Question

Redirect tomcat to https using apache server (Windows)

I need to integrate apache server with tomcat first and then redirect http request to https using apache in localhost.


  1. I have a java web development project running on tomcat server. let the url be http://localhost:8080/myProject

  2. I need to integrate my tomcat server with apache server such that http://localhost/myProject displays the page http://localhost:8080/myProject

  3. I need to add security certificate and make it a https request i.e., if i type http://localhost/myProject it should direct to https://localhost/myProject and display the page shown in http://localhost:8080/myProject.

I am able to integrate the two servers successfully using mod_jk and i have installed the self signed security certificate using mod_rewrite and by specifying the certificate and key in httpd-ssl.conf file.
this is the file which i have included in httpd.conf:

# Load mod_jk module
# Update this path to match your modules location
LoadModule jk_module "C:/Program Files/BitNami WAMPStack/apache2/modules/"

# Where to find
# Update this path to match your conf directory location
JkWorkersFile C:/softwares/apache-tomcat-7.0.42/conf/

# Where to put jk logs
# Update this path to match your logs directory location
JkLogFile C:/MyProject/mod_jk.log

# Set the jk log level [debug/error/info]
JkLogLevel info

# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"

# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://localhost$1 [R,L]

# Send everything for context /myProject to worker ajp13
JkMount /myProject ajp13
JkMount /myProject/* ajp13

Problem faced:
On removing the lines,

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://localhost$1 [R,L]

it successfully displays the page as an http request. But on adding the line, though it redirects to an https request it gives a "Not Found" error. I am not able to figure out how to correct this. I hope i am able to explain the problem. I am new to servers and apache modules so this may be a very lame question but please help me figure this out.

Answer Source

There was a tag "< VirtualHost default:443>" in httpd-ssl.conf file. I added the following statement at the end of the tag and it worked.

<VirtualHost _default_:443> 
    JkMount /myProject ajp13
    JkMount /myProject/* ajp13