1

I use a router which distributes internet to 3 PCs through NAT. I have forwarded port 8008 of my router to my PCs port 3127. When I host my site on port 3127, it is visible at

example.com:8008

. However, even though it is default port of http, I cannot see my site on default domain i.e. http://example.com

I use a dlink router.

I want to add a script in my router similar to below, how to do it?

if (http_packet.host == "*example.com*"):   #contains example.com
    forward(port8008)
4
  • 1
    this probably isn't going to be possible with a consumer grade router. what you are asking about is usually a feature of a Web Application Firewall (WAF) and are common in Load Balancers and reverse proxies. You are probably going to havce to just forward the port, and allow the webserver to handle no-site-here requests. Note also that you can't generally test a port forwarding rule from inside your LAN, unless your router supports Hairpinning, which is uncommon on consumer grade routers. Jun 15, 2020 at 6:08
  • Didn't get your 2nd point. If I forward the port, I will always have to access my site from example.com:8008, right? The request will just reach my router and not my server. If I forward port 80, I fear other computers will not be able to access http sites. Also, if 8008 is an http port, why isn't my site visible? Jun 15, 2020 at 6:23
  • 2
    Port 8008 is not the default port for http. Port 80 is, and 443 for https.
    – davidgo
    Jun 15, 2020 at 6:55
  • forwarding 80 as DNAT is unlikely to interfere with your internal hosts web browsing if that's what you are asking. that said, 8080 should be fine, providing that when you map it to 3127, that there is a process on that port listening for requests from 0.0.0.0. on your webserver, is the port open to 0.0.0.0? for powershell as admin netstat -abno | findstr LISTENING | findstr 3127 or in linux netstat -ntlup | grep 3127. as for my comment on Hairpinning, you may find that your site works if you try to access it from the coffee shop. normally you can't request port forwarding from a lan host Jun 15, 2020 at 7:00

1 Answer 1

1

However, even though [8008] is default port of http, I cannot see my site on default domain i.e. http://example.com.

Port 80 (HTTP) and port 443 (HTTPS) are the only standard ports for HTTP/HTTPS.

If 8008 is an http port, why isn't my site visible?

As mentioned, 8008 isn't an official HTTP port. Typing http://example.com in a browser is no different than typing http://example.com:80. Other ports such as 81, 8008 and 8080 are often used simply because they are visually similar to 80 and aren't in use themselves (in most cases).

If I forward port 80, I fear other computers will not be able to access http sites.

Most communications on port 80 should not be blocked if a request for an HTTP site originates in your network (ex. from a browser on a local machine), even if you are forwarding port 80.

Requests originating outside your network (i.e. someone trying to contact your website) will be forwarded to whatever host you forward port 80 to, but this host can then potentially redirect requests to other hosts or ports (if needed).

if (http_packet.host == "*example.com*"): #contains example.com
    forward(port8008)

This type of redirection can be done but generally is done through a reverse proxy (the host receiving the request, above).

5
  • 1
    Thanks, this is very helpful. If I hear your advice correctly, I have no choice except forward port 80. I want to set up a uwsgi server initially with http, then with https which would connect directly. I didn't find configuring nginx as reverse proxy an easy task. It's documentation is too bad. I presume that since other PCs will not be serving anything, they will be the ones sending request and getting response and very few if any request will be received by them. Jun 15, 2020 at 15:36
  • You're welcome. Your assessment seems accurate. Regarding port 80, if you want http://example.com to be available in a browser without a port number attached to it, no, unfortunately you don't have a choice except to forward port 80. Regarding the other PCs, they should not receive any intial incoming requests at all. Only the host you forward port 80 to in your router should receive those incoming requests. Jun 15, 2020 at 23:47
  • About reverse proxy servers, I agree with you regarding Nginx. Anecdotally, I have always found Nginx a poor choice for ease of setup. I personally much prefer Apache. It feels easier to understand and more straightforward to me. Jun 15, 2020 at 23:48
  • so if one types example.com , you said it is nothing but example.com:80. If example.com is a https site, say on port 443, and one types just example.com in browser without http or https, will one have to redirect 80 to 443 or it automatically sees 443? Is there a default request built in browser? Jun 16, 2020 at 6:48
  • 1
    "Will one have to redirect 80 to 443?" - Yes. When typing just ex. example.com into a browser (without http:// or https://), most browsers will usually assume an http:// connection (port 80), since not all sites have an https:// version. Your server will need to listen to port 80 and issue a redirect when requests are received on that port, so that the browser will know to reconnect on port 443 with https://. Jun 16, 2020 at 21:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .