2
votes

I have two docker containers:

  1. One container runs my spring boot application which listens on port 8080: This container exposes 8080 port to other docker containers. Container ip in the docker network is 172.17.0.2.
  2. The other container runs nginx which publishes port 80.

I can successfully put my spring boot app behind nginx with the following conf in my nginx container:

server {

server_name <my-ip>;

listen 80;

location / {
    proxy_pass http://172.17.0.2:8080/;
}

}

Doing a GET request to my REST API (http://my-ip/context-url) works fine.

I am trying now to put my application behind nginx with https. My nginx conf is as follows:

server {

    server_name <my-ip>;

    listen 80;

    return 301 https://$server_name$request_uri;

}

server {

   server_name <my-ip>;

   listen 443;

   ssl on;
   ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
   ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;

   location / {
        proxy_pass http://172.17.0.2:8080/;
    }
}

However I cannot access my application now either through http or https. http redirects to https and result is ERR_CONNECTION_REFUSED

1
Are you sure that your nginx is restarting? Test the configuration using nginx -T. IDK if you can build a secure server using its IP address as a name. - Richard Smith
I don't need to restart it. I do nginx reload and configuration changes. - dane131

1 Answers

0
votes

Problem was that I was not publishing 443 port when running nginx container but only port 80.The nginx configuration is right.