Try the following:
server {
listen 80;
server_name sub.domain.com;
location / {
proxy_pass http://127.0.0.1:8081;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
localhost
may not necessarily resolve to 127.0.0.1
which is where your Docker container is listening.
Make sure you can get to port 8081
from your machine. Run:
$ telnet 127.0.0.1 8081
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.