I am in a very unusual situation and I have spent almost 8 hours trying to figure out what the problem is.
The setup
I have a server running Debian 11. Inside this server, I have a setup a CentOS virtual machine with KVM. The virtual machine hosts a complex web application behind an Apache server. The network interface of the KVM is NAT and therefore to access the web application, I have setup port forwarding rules using libvirt
hooks as described here:
https://wiki.libvirt.org/page/Networking#Forwarding_Incoming_Connections
My setup forwards any incoming connections to port 443 to the Apache server on the Virtual Machine and this is working fine.
I have also set up an Nginx server on the host machine as I intend to use it as a reverse proxy. I will be hosting another application on the host server on port 9000. Using the Nginx for reverse proxy, I plan to redirect redirect all requests to https://example.com
to the Virtual Machine and all requests to https://example.com/app/
to the web application running on port 9000.
The problem
I installed the Nginx server after setting up the Virtual Machine and its corresponding Port forwarding rules. But when I try to run the Nginx server's start page, it is not reachable. I understand that port 443 gets forwarded to the VM. So, I try to load with http://example.com
expecting it to load the Nginx start page on port 80. But it keeps telling that the website is unreachable.
What I have tried so far?
I suspected that the port forwarding rules from the host to the guest might be the root cause here. So I changed the port forward rule from port 443 to 8000. So any requests to port 8000 would be forwarded to the Apache server on the VM. But after doing this, port 443 became unreachable as well.
I tried to completely clear the iptables as described here:
Clear and reset iptables in Debian
But still, the Nginx server remains unreachable.
Also, very strangely, after clearing the iptables, when I try to access the application running on port 9000 with http://example.com:9000
I get a 400 Bad request error
and when I change the protocol to https
, the page becomes unreachable.
Any advice would be very helpful. Thank you.