This is because the web application sees all remote addresses as localhost when it is served publicly with a host name. To solve this problem, we configure Nginx to reverse proxy - a way to trick the web application that all access to it or the remote addresses accessing it is from the IP of the host or the host name instead.
Here's the configuration from https://www.digitalocean.com/community/tutorials/understanding-nginx-http-proxying-load-balancing-buffering-and-caching
location /match/here {
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://example.com/new/prefix;
}
For more information, please visit https://www.nginx.com/.