My configuration is as follows: Ubuntu, Nginx, Apache Tomcat 8. I only use Tomcat to run a servlet that queries MySQL and returns JSON. My web pages are served through Nginx. Then I installed LetEncrypt to Nginx. I enabled SSL/TLS encryption mode (Full (strict)) in CloudFlare. My Servlet is working fine when I use port 8080, and return the JSON response. To make it secure I changed Tomcat server.xml connector :
<Connector port="8443"
protocol="org.apache.coyote.http11.Http11AprProtocol"
maxThreads="150"
SSLEnabled="true"
maxParameterCount="1000"
URIEncoding="UTF-8"
>
<UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
<SSLHostConfig>
<Certificate certificateFile="/etc/letsencrypt/live/<my-domain>/cert.pem"
certificateKeyFile="/etc/letsencrypt/live/<my-domain>/privkey.pem"
certificateChainFile="/etc/letsencrypt/live/<my-domain>/chain.pem" />
</SSLHostConfig>
</Connector>
and commented
<!-- Connector port="8080"
Restarted tomcat, but I’m still able to invoke the tomcat servlet directly using 8080 port. But, when I call it from Ajax in my web page, I get this error: net::ERR_SSL_PROTOCOL_ERROR
My Question: How to allow my servlet to be called only from my web page.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hey @walsayer,
From what you’ve written, it seems like you just need to configure your Nginx as a reverse proxy to Tomcat for everything to work. Your Nginx configuration file (usually located at
/etc/nginx/sites-available/default
or/etc/nginx/conf.d/your_domain.conf
) should include the following:Replace
/servlet_path
with the actual path to your servlet. This configuration will forward requests from Nginx to your Tomcat server over HTTPS, using the same SSL certificates. Note that you’ll need to have thengx_http_proxy_module
andngx_http_ssl_module
modules enabled in Nginx.