I can access my server running in a Docker container w/ port 0.0.0.0:8080 and 0.0.0.0:5432 (for accessing remote Postgres server on ElephantSQL). I had this running @ one point behind an NGINX server in DigitalOcean but had to recreate my droplet and now I can’t get the config to work again .. ugh!.

I CAN access my server via http://dropletIP:8080

When I run my server in a container on my MCB and I run the following NGINX server & configuration on my MCB in another container, I access my server with http://localhost:80.

But when I run the same configuration and servers in my droplet:
http://dropletIP:8080 … my server is working but
MyDomain.com … server does does not response.

Also.. I have MyDomain pointing its A record to www.MyDomain.com and MyDomain.com

Here is my default (no extension) which I have located in \etc\nginx\sites-enabled. (Note: there are no config files in config.d and the default file in sites-available is a mirror of the default config file in sites-enabled.

server {
    listen  [::]:80;
    server_name MyDomain.com www.MyDomain.com;

    location / {
        proxy_pass http://localhost:8080;
#       proxy_set_header Connection "upgrade";
#        proxy_set_header Host $host;
 #       proxy_set_header X-Real-IP $remote_addr;
 #       proxy_cache_bypass $http_upgrade;
 #       proxy_set_header Upgrade $http_upgrade;
        proxy_connect_timeout 60s;
        proxy_send_timeout 60s;
        proxy_read_timeout 60s;
    }
}

my ufw status:

22/tcp                     LIMIT       Anywhere                  
2375/tcp                   ALLOW       Anywhere                  
2376/tcp                   ALLOW       Anywhere                  
5432                       ALLOW       Anywhere                  
Nginx HTTP                 ALLOW       Anywhere                  
80                         ALLOW       Anywhere                  
8080                       ALLOW       Anywhere                  
443                        ALLOW       Anywhere                  
22/tcp (v6)                LIMIT       Anywhere (v6)             
2375/tcp (v6)              ALLOW       Anywhere (v6)             
2376/tcp (v6)              ALLOW       Anywhere (v6)             
5432 (v6)                  ALLOW       Anywhere (v6)             
Nginx HTTP (v6)            ALLOW       Anywhere (v6)             
80 (v6)                    ALLOW       Anywhere (v6)             
8080 (v6)                  ALLOW       Anywhere (v6)             
443 (v6)                   ALLOW       Anywhere (v6)   

and my server container:
0.0.0.0:5432->5432/tcp, 0.0.0.0:8080->8080/tcp

edited by MattIPv4

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

Hi @Drunner4,

After digging around, I found the following article :

https://www.docker.com/blog/how-to-use-the-official-nginx-docker-image/

It describes what exactly you are trying to do. As far as I can see, the Nginx configuration file should look something like :

server { 
 listen 80;
 server_name frontend;
 location / {
   # This would be the directory where your app's static files are stored at
   root /usr/share/nginx/html;
   try_files $uri /index.html;
 }

 location /services/m {
   proxy_set_header X-Real-IP $remote_addr;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   proxy_set_header X-NginX-Proxy true;
   proxy_pass http://backend:8080/services/m;
   proxy_ssl_session_reuse off;
   proxy_set_header Host $http_host;
   proxy_cache_bypass $http_upgrade;
   proxy_redirect off;
 }
}

Now, in this case it’s using a frontend and backend for different files. You can remove the backendstuff and make it with localhost.

Anyway, the thing that you are missing in your initial configuration file is the location of the files it should use. That’s it.

Regards,
KFSys

Submit an Answer