简体   繁体   中英

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.

Explaination:

  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 ie, 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/mod_jk.so"

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

# 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.

Maybe your Apache HTTPD is listening only to port 80, and when you request a https://localhost/ without declaring a port your browser is requesting standard https port 443.

So, please check if you are listening to both ports 80 and 443 in your httpd.conf or just 80. If only 80, adding 443 on listen sentence in Listen statement should resolve the issue

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 
</VirtualHost>

These configurations are very simple. But,in all the websites one important part is missing. ie Please map the servername defined in the virtualhosts file with the ipaddress in the hosts file C:/Program files x86/drivers/etc/hosts . Eg. 127.0.0.1 localhost (if no virtual host) 127.0.0.1 proxyportal.company.com (if server name in tag is proxyportal.company.com)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM