1

I tried to forward port 80 & 443 to 8080 on a server that I am working on https://www.neptos.io

My Angular Universal app is running on 8080 but my default angular app is running on port 80 & 443 (https)

I forwarded both port 80 and 443 to 8080 via iptables using:

iptables -t nat -A OUTPUT -o lo -p tcp --dport 80 -j REDIRECT --to-port 8080
iptables -t nat -A OUTPUT -o lo -p tcp --dport 443 -j REDIRECT --to-port 8080

Now when I ssh into the remote machine and run curl localhost, I get the desired result which is the angular universal app but when I open, it in a browser https://www.neptos.io I get the default angular app.

Am i doing something wrong here?

Any help would be appreciated.

Rojan Shrestha
  • 212
  • 4
  • 7
  • 1
    Its' not possible make HTTP and HTTPS listen on same port. What you can do is accept all request on http and do internal redirect to https connection.There is no DIRECT way to achieve HTTP and HTTPS on same port. – Mukesh Verma Jan 07 '19 at 05:25

1 Answers1

0

I believe the OUTPUT chain will only effect traffic generated on the localhost. To redirect incoming traffic you need to use the PREROUTING chain.

iptables -t nat -I PREROUTING --src 0/0 --dst 127.0.0.1 -p tcp --dport 80 -j REDIRECT --to-ports 8080

Just replace the localhost ip with what ever your interface IP is

Classified
  • 232
  • 1
  • 6
  • This seems to have gotten the redirect to work properly but now the website only works using http and not https? – Rojan Shrestha Jan 07 '19 at 05:37
  • That's because as mentioned above there is no DIRECT way you could run HTTP and HTTPS on same port. – Mukesh Verma Jan 07 '19 at 05:43
  • any idea how i would run https on port 8080 and 443 for this? – Rojan Shrestha Jan 07 '19 at 05:50
  • https://stackoverflow.com/questions/22453782/nodejs-http-and-https-over-same-port – Mukesh Verma Jan 07 '19 at 05:58
  • Why do you need HTTPS and HTTP on the same port?? Is it so if a user hits the site on HTTP you want to redirect to HTTPS? Or do you really want HTTP traffic also? If it is the former I usually run nginx as a reverse proxy and redirect all HTTP traffic to HTTPS. If the latter check the post that Mukesh linked. – Classified Jan 07 '19 at 06:25
  • I followed Mukesh's advice and got this to work by shutting down apache and running the app directly on 443 port and redirecting port 80 to port 443 with https but my Angular Universal server side rendering app can't seem to make a request to its local api, I am using full urls and not api urls. – Rojan Shrestha Jan 09 '19 at 03:12