Setting up an nginx reverse proxy server for SSL connections on a remote virtual machine, with Apache tomcat

Thank you for your response!

Was that advice with or without the nginx reverse proxy? Because for with the reverse proxy in situ, one would think this iptables stuff completely bypasses the nginx proxy on port 443 and 80? I'm surprised your Certbot certificate issuance even worked.

The certificate was issued by certbot when I was still attempting to use Apache tomcat alone. I re-installed it for nginx with sudo certbot --nginx. There was a prompt "would you like to reconfigure your existing certificate?" I chose yes, and it reported success. I have now turned off the port forwarding, using sudo iptables -t nat -D PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080, sudo iptables -t nat -D PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 8443, sudo iptables -t nat -D OUTPUT -o lo -p tcp --dport 80 -j REDIRECT --to 8080, and sudo iptables -t nat -D OUTPUT -o lo -p tcp --dport 443 -j REDIRECT --to 8443.

Also, are Tomcat and nginx running on the same server? If so, it's probably better to have your reverse proxy configured to connect to 127.0.0.1 . And it doesn't require HTTPS on Tomcats side, that's whats nginx is for. It's probably better to just have Tomcat configured as a "plain HTTP" server, nothing more, nothing less and let nginx do all the rest.

I see what you mean. Yes, they are on the same server. I've changed the nginx configuration line to:

proxy_pass http://127.0.0.1;

In Tomcat I have changed the Connector to:

    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               maxParameterCount="1000"
               />

I'm still getting "refused to connect" for https.