I have my Vapor App MyApp
running on localhost:8080
on my Ubuntu server and installed nginx to connect to it via <server-ip>:80
.
It works, but I don't understand the following part of it:
To get it to work I followed a small tutorial on how to host a Vapor app. A part of an nginx config file had to be set up like:
server {
listen 80 default_server;
listen [::]:80 default_server;
location / {
proxy_pass http://127.0.0.1:8080;
}
}
I now should've been able to reach MyApp
using <server-ip>:80
, but this didn't work. As MyApp
starts with the prompt:
Server starting on http://localhost:8080
I changed the server block in the nginx config to:
server {
listen 80 default_server;
listen [::]:80 default_server;
location / {
proxy_pass http://localhost:8080; // Changed to localhost
}
}
This worked and I am now able to reach MyApp
!
netstat shows the following entries:
[...]:~# netstat -antp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1106/nginx: master
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 601/systemd-resolve
[...] // my ssh connection
tcp6 0 0 ::1:8080 :::* LISTEN 8145/<MyApp>
tcp6 0 0 :::80 :::* LISTEN 1106/nginx: master
- So it seems my Vapor app runs on tcp6. I'm new to server development and thought of localhost as an equivalent to
127.0.0.1
. Why did my changes make it work? - With my change to localhost, might I run into any other problems?