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>
<!-- 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.
Click below to sign up and get $200 of credit to try our products over 60 days!
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/conf.d/your_domain.conf) should include the following:
/servlet_pathwith 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 the
ngx_http_ssl_modulemodules enabled in Nginx.