简体   繁体   中英

Forward Apache ssl port 443 to Tomcat http port

I have my tomcat running as standalone in my linux box on port 7778. I have configured apache to run on ssl on port 443.

My httpd.conf is as below:

    Listen 80
<VirtualHost *:80>
    ServerName www.domain.com
    Redirect / https://www.example.com
</VirtualHost> -->
ProxyPass         /  http://localhost:7778/website
ProxyPassReverse  /  http://localhost:7778/website

My ssl.conf is as below:

Listen 443
<VirtualHost _default_:443>
SSLEngine on
SSLCertificateFile    /path/to/certificate/file
SSLCertificateKeyFile /path/to/key
</VirtualHost>

My server.xml connector is as below:

<Connector port="7778" protocol="HTTP/1.1"
                proxyName="www.domain.com" proxyPort="80" />

Issue is my Apache is not able to redirect to Tomcat on 7778 port and gives 503 error.

Two steps:

1 Firts confirm your Tomcat is ok.

Make sure you can connect to http://localhost:7778/website and get the expected response.

Then, for proxy support modify your Connector:

<Connector port="7778" protocol="HTTP/1.1" proxyName="www.example.com" proxyPort="80" />

2 Fix your Apache configuration

Here I assume:

  • when you try http://www.example.com you are redirected to https://www.example.com
  • when you try https://www.example.com you get the response from Tomcat

    Listen 80 <VirtualHost *:80> ServerName www.example.com ServerAlias example.com CustomLog "logs/80_access.log" combined ErrorLog "logs/80_error.log" Redirect / https://www.example.com </VirtualHost> <VirtualHost *:443> ServerName www.example.com ServerAlias example.com # While debugging LogLevel debug CustomLog "logs/443_access.log" combined ErrorLog "logs/443_error.log" SSLEngine On SSLCertificateFile /path/to/certificate/file SSLCertificateKeyFile /path/to/key # Proxy to Tomcat ProxyRequests Off ProxyPass / http://localhost:7778/website ProxyPassReverse / http://localhost:7778/website </VirtualHost>

What you may have to adjust

  • Log files directory
  • certificate files directory
  • LogLevel, remove debug mode once it works
  • Make sure required modules are loaded. apachectl -t will let you know if you are missing any.

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