Tomcat – HTTPS proxy in apache for rest API

apache-2.2confPROXYtomcat

Sounds like a basic question, but I don't know about apache config. Any help would be great.

Since Open TSDB wont support https to send data(via REST API), we want to create a https proxy in apache or "Apache Tomcat". For example, the local machine has both TSDB and Apahce. The apache should accept http and https, if I send any to https://<PUBLIC IP>/api/input, it should forward to TSDB in that same machine (Or TSDB could be in different machine) with http.

The big picture

MY Code<—->https://<PUBLIC IP>/api/input<—-Proxy to—->http://localhost/api/input

Above I mentioned Apache Tomcat because, mainly we are using Apache Tomcat for other purpose so, first priority is Tomcat(Is it possible with Tomcat?).

NOTE: I know the difference between Apache and Apache Tomcat: Apache is http web server handles the http traffic only, tomcat is servelet container to process the request(For Java only). In build Tomcat has Apache.(Please correct me, if I am wrong)

Best Answer

In Apache HTTPD basically it would be like this:

<VirtualHost *:80>
ServerName publicname.example.com
Redirect / https://publicname.example.com/
</VirtualHost>

<VirtualHost *:443>
ServerName publicname.example.com
SSLEngine on
SSLCertificateFile /path/to/cert.pem
SSLCertificateKeyFile /path/to/key.pem
ErrorLog /path/to/logs/publicaname.example.com-ssl-error.log
CustomLog /path/to/logs/publicaname.example.com-ssl.log combined

ProxyPass /api/input http://127.0.0.1:8080/api/input
ProxyPassReverse /api/input http://127.0.0.1:8080/api/input
</VirtualHost>

Note: you will need mod_proxy and mod_proxy_http modules loaded first.

Related Topic