[Solved] Open ports 80 and 443 to the public internet

I'm trying to make a few web apps available to the public internet while I'm running the server on my computer but I'm not having any success despite the effort.

This is how my firewall is configured:


I tried to allow forwarding between wan to lan zones and adding two traffic rules to allow any traffic on ports 80 and 443 from any source on wan to my specific machine on lan, but it didn't work, so I revert back those changes. I have a custom domain pointing to my wan's public address and a tls certificate issued using acme.sh and DNS-01 challenge. I thought everything was already working because I can access my web app inside any devices in lan using the custom domain and be served correctly but nothing works when I use another upstream connection. I'm not sure if it's something related to my ISP and I don't know how to confirm that, so any help is welcome.

Ignoring the security risks for opening those ports, make sure that the WAN device has your public IP and not another like when being behind a CGNAT (192.xxx.xxx.xx range).

If your WAN device does have your public IP address (the one you could see on whatsmyip.com), maybe your ISP blocks port 80. Try with 8080 or something else and see if you can access your local device from the internet.

You can test it with your phone using mobile data.

The rules are fine, maybe it's the ISP.

Please post just the first two octets (in bold: aaa.bbb.ccc.ddd) of the following:

ifstatus wan | grep address

The IP address that shows on IPv4 upstream on LuCI is the same as it shows on any "My IP address" websites.

1 Like

Let’s take a look at your config:

Please connect to your OpenWrt device using ssh and copy the output of the following commands and post it here using the "Preformatted text </> " button:
grafik
Remember to redact passwords, MAC addresses and any public IP addresses you may have:

ubus call system board
cat /etc/config/network
cat /etc/config/firewall

address: 179.51.xxx.xxx
ptpaddress: 186.231.xxx.xxx

1 Like

You have a public IP, so that is good!

1 Like

Is your destination zone on the redirect set to lan?

My router is a Redmi AX6 running in the latest version available 23.05.5 (24 won't take long).

Network:

config interface 'loopback'
        option device 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config globals 'globals'
        option ula_prefix 'fd46:2d9a:b567::/48'

config device
        option name 'br-lan'
        option type 'bridge'
        list ports 'lan1'
        list ports 'lan2'
        list ports 'lan3'

config interface 'lan'
        option device 'br-lan'
        option proto 'static'
        option ipaddr '192.168.1.1'
        option netmask '255.255.255.0'
        option ip6assign '60'
        list dns '1.1.1.1'
        list dns '1.0.0.1'

config interface 'wan'
        option device 'wan'
        option proto 'pppoe'
        option username 'guest'
        option password 'guest'
        option ipv6 'auto'

and firewall:

config defaults
        option input 'REJECT'
        option output 'ACCEPT'
        option forward 'REJECT'
        option synflood_protect '1'

config zone
        option name 'lan'
        option input 'ACCEPT'
        option output 'ACCEPT'
        option forward 'ACCEPT'
        list network 'lan'

config zone
        option name 'wan'
        option input 'REJECT'
        option output 'ACCEPT'
        option forward 'REJECT'
        option masq '1'
        option mtu_fix '1'
        list network 'wan'

config forwarding
        option src 'lan'
        option dest 'wan'

config rule
        option name 'Allow-DHCP-Renew'
        option src 'wan'
        option proto 'udp'
        option dest_port '68'
        option target 'ACCEPT'
        option family 'ipv4'

config rule
        option name 'Allow-Ping'
        option src 'wan'
        option proto 'icmp'
        option icmp_type 'echo-request'
        option family 'ipv4'
        option target 'ACCEPT'

config rule
        option name 'Allow-IGMP'
        option src 'wan'
        option proto 'igmp'
        option family 'ipv4'
        option target 'ACCEPT'

config rule
        option name 'Allow-DHCPv6'
        option src 'wan'
        option proto 'udp'
        option dest_port '546'
        option family 'ipv6'
        option target 'ACCEPT'

config rule
        option name 'Allow-MLD'
        option src 'wan'
        option proto 'icmp'
        option src_ip 'fe80::/10'
        list icmp_type '130/0'
        list icmp_type '131/0'
        list icmp_type '132/0'
        list icmp_type '143/0'
        option family 'ipv6'
        option target 'ACCEPT'

config rule
        option name 'Allow-ICMPv6-Input'
        option src 'wan'
        option proto 'icmp'
        list icmp_type 'echo-request'
        list icmp_type 'echo-reply'
        list icmp_type 'destination-unreachable'
        list icmp_type 'packet-too-big'
        list icmp_type 'time-exceeded'
        list icmp_type 'bad-header'
        list icmp_type 'unknown-header-type'
        list icmp_type 'router-solicitation'
        list icmp_type 'neighbour-solicitation'
        list icmp_type 'router-advertisement'
        list icmp_type 'neighbour-advertisement'
        option limit '1000/sec'
        option family 'ipv6'
        option target 'ACCEPT'

config rule
        option name 'Allow-ICMPv6-Forward'
        option src 'wan'
        option dest '*'
        option proto 'icmp'
        list icmp_type 'echo-request'
        list icmp_type 'echo-reply'
        list icmp_type 'destination-unreachable'
        list icmp_type 'packet-too-big'
        list icmp_type 'time-exceeded'
        list icmp_type 'bad-header'
        list icmp_type 'unknown-header-type'
        option limit '1000/sec'
        option family 'ipv6'
        option target 'ACCEPT'

config rule
        option name 'Allow-IPSec-ESP'
        option src 'wan'
        option dest 'lan'
        option proto 'esp'
        option target 'ACCEPT'

config rule
        option name 'Allow-ISAKMP'
        option src 'wan'
        option dest 'lan'
        option dest_port '500'
        option proto 'udp'
        option target 'ACCEPT'

config redirect
        option dest 'lan'
        option target 'DNAT'
        option name 'Xbox Live'
        list proto 'udp'
        option src 'wan'
        option src_dport '88'
        option dest_ip '192.168.1.125'
        option dest_port '88'

config redirect
        option dest 'lan'
        option target 'DNAT'
        option name 'Xbox Live'
        option src 'wan'
        option src_dport '3074'
        option dest_ip '192.168.1.125'
        option dest_port '3074'

config redirect
        option dest 'lan'
        option target 'DNAT'
        option name 'Xbox Live'
        option src 'wan'
        option src_dport '53'
        option dest_ip '192.168.1.125'
        option dest_port '53'

config redirect
        option dest 'lan'
        option target 'DNAT'
        option name 'Xbox Live'
        list proto 'udp'
        option src 'wan'
        option src_dport '500'
        option dest_ip '192.168.1.125'
        option dest_port '500'

config redirect
        option dest 'lan'
        option target 'DNAT'
        option name 'Xbox Live'
        list proto 'udp'
        option src 'wan'
        option src_dport '3544'
        option dest_ip '192.168.1.125'
        option dest_port '3544'

config redirect
        option dest 'lan'
        option target 'DNAT'
        option name 'Xbox Live'
        list proto 'udp'
        option src 'wan'
        option src_dport '4500'
        option dest_ip '192.168.1.125'
        option dest_port '4500'

config redirect
        option dest 'lan'
        option target 'DNAT'
        option name 'Web'
        option family 'ipv4'
        list proto 'tcp'
        option src 'wan'
        option src_dport '80'
        option dest_ip '192.168.1.100'
        option dest_port '80'

config redirect
        option dest 'lan'
        option target 'DNAT'
        option name 'Web'
        option family 'ipv4'
        list proto 'tcp'
        option src 'wan'
        option src_dport '443'
        option dest_ip '192.168.1.100'
        option dest_port '443'

config rule
        option name 'Allow-HTTPS'
        list proto 'tcp'
        option src 'wan'
        option src_port '443'
        option dest 'lan'
        option dest_port '443'
        option target 'ACCEPT'
        option family 'ipv4'

config rule
        option name 'Allow-HTTP'
        list proto 'tcp'
        option src 'wan'
        option src_port '80'
        option dest 'lan'
        option dest_port '80'
        option target 'ACCEPT'
        option family 'ipv4'

These rules are the ones you should keep, but you need to add the following to each:

        option dest 'lan'

And delete these two:

1 Like

Not sure if I'm following you. I deleted those two traffic rules and the rest should I define destination lan on all of them?

The two redirect rules need the destination of the lan firewall zone. Just add that and it should work. Don't forget to reboot the router to make sure the edits become active.

Post the updated firewall config if it still isn't working properly.

Both firewall redirect rules already have the option dest 'lan' specified.

oh... you're right... sorry, I missed those.

Ok... so you deleted the others and rebooted, right? Does it work?

It doesn't work but I only deleted the two traffic rules I created today. The rest is all the same. That's what I asked, should I delete all the other traffic rules added by openwrt? or all the Xbox Live redirect rules?

No... leave all the default rules alone.

If you don't need those rules, then yes, delete them. Otherwise they're probably fine. There is one, though, that seems unnecessary and possibly bad (unrelated to your current issue)... I would delete this one:

Back to your current issue:

  1. How are you testing the port forward?
  2. While connected to your lan, can you open a browser and reach https://192.168.1.100 and http://192.168.1.100?

I don't. If I can reach my web app I believe it's working.

My web browser will render a HTTP 503 error as nginx was configured to, for the default server, and a certificate error when accessing using https.

server {
    server_name _; # This is just an invalid value which will never trigger on a real hostname.
    server_tokens off;
    access_log /var/log/nginx/access.log vhost;
    http2 on;
    listen 80;
    listen [::]:80;
    listen 443 ssl;
    listen [::]:443 ssl;
    ssl_session_cache shared:SSL:50m;
    ssl_session_tickets off;
    # No default certificate found, so reject SSL handshake;
    ssl_reject_handshake on;
    location ^~ / {
        return 503;
    }
}

upstream myapp.example.com {
    # Container: myapp
    #     networks:
    #         dev (reachable)
    #     IPv4 address: 172.18.0.8
    #     IPv6 address: (none usable)
    #     exposed ports (first ten): 5173/tcp 8000/tcp
    #     default port: 80
    #     using port: 8000
    server 172.18.0.8:8000;
    keepalive 2;
}
server {
    server_name myapp.example.com;
    access_log /var/log/nginx/access.log vhost;
    listen 80 ;
    listen [::]:80 ;
    # Do not HTTPS redirect Let's Encrypt ACME challenge
    location ^~ /.well-known/acme-challenge/ {
        auth_basic off;
        auth_request off;
        allow all;
        root /usr/share/nginx/html;
        try_files $uri =404;
        break;
    }
    location / {
        return 301 https://$host$request_uri;
    }
}
server {
    server_name myapp.example.com;
    access_log /var/log/nginx/access.log vhost;
    http2 on;
    listen 443 ssl ;
    listen [::]:443 ssl ;
    ssl_session_timeout 5m;
    ssl_session_cache shared:SSL:50m;
    ssl_session_tickets off;
    ssl_certificate /etc/nginx/certs/myapp.example.com.crt;
    ssl_certificate_key /etc/nginx/certs/myapp.example.com.key;
    ssl_dhparam /etc/nginx/certs/myapp.example.com.dhparam.pem;
    ssl_stapling on;
    ssl_stapling_verify on;
    ssl_trusted_certificate /etc/nginx/certs/myapp.example.com.chain.pem;
    set $sts_header "";
    if ($https) {
        set $sts_header "max-age=31536000";
    }
    add_header Strict-Transport-Security $sts_header always;
    location / {
        proxy_pass http://myapp.example.com;
        set $upstream_keepalive true;
    }
}

So I have an web app myapp that is running inside a docker container and a nginx container listen on ports 80 and 433 on my machine (192.168.1.100) proxying all the traffic to the correct server (web apps). When I access myapp.example.com on my computer or phone everything works, but when I change my phone's connection, I can't access myapp.example.com anymore. So I think it's something to do with my router configuration or even my ISP blocking those ports. They could do this, couldn't they?

Since you're now dealing with more complex situations than just serving a basic website, I'd recommend that you go back to the simple case...

Setup a web server on a computer on your lan (a pi or similar would be perfect). Verify that it works when connecting locally, and then, point the port-forward to that host. Test to see if you can reach the server from outside your network. This simple case will be easier to test/debug than your web app proxy thing.

Ok. I stopped all docker containers and started a caddy container with port 80 published, so when I access 127.0.0.1 or localhost, the browser serves its default welcome page:

If I try to access it using the public address given by my ISP it should serve me the same page, but I get no response. If I run the same test in a cloud server like Oracle or AWS it works as expected. So it means the problem is my ISP or router configuration. Tried using port 8080 too and no response either.

Are you able to reach the page from another computer on the lan (pointed at the internal IP address of the server host)?