Search code examples
windowsnginxwebnginx-reverse-proxy

Nginx Reverse Proxy For Web App Hosted on Local Server


I am hosting a web application via a home server. I have my Cloudflare DNS A record pointed to my public ip and my firewall is off. I am using cloud flare for SSL.

My app is running on local host (127.0.0.1) port 1624.

I am using nginx. My server name is my public ip and listen is port 80.

My reverse proxy is pointed at 127.0.0.1:1624. I have port 80 open on my router as well.

For some reason I am not able to connect to my website. What could be causing this?

The developer of the web app has told me to use my domain name for the server name and keep the port as default 80 while pointing the reverse proxy to 127.0.0.1:1624.

My nginx conf:

server 
{
    server_name {mypublicip};
    #server_name {mydomainname};
    listen       80;

    location / {
            proxy_pass http://127.0.0.1:1624; # my web app proxy

            proxy_http_version 1.1;
            proxy_set_header Host $host:$server_port;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
        }

    #error_page  404              /404.html;
    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}

}

Router Settings: Router Settings

I've tried:

Nginx conf -

  • server_name > domain NAME
  • server_name > public ip

My app is working when I go to 127.0.0.1:1624 just not my domain.


Solution

  • You should configure port forwarding on your router - so that all packets coming on port 80 of the public IP on your router will be forwarded to port 80 of your local PC (which probably has an internal IP address in a 192.168.xx.yy range). Then your nginX should listen on port 80 at that 192.168.xx.yy address on your PC and proxy_pass to 127.0.0.1:1624 where your application is listening.

    IF you don't do this - packets will end up on the router instead of at nginX in your local PC.