0
votes

I am using Docker and have separate containers for NGINX and also Grafana. I am trying to ultimately have the connection to the browser be HTTPS and be able to see the Grafana site. I will need 3 things for this to happen but no matter how much I Google I cannot get this to work.

  1. Switch all HTTP traffic going to NGINX to HTTPS
  2. Have NGINX reverse proxy that HTTPS traffic to Grafana container.

These again are in Docker containers. I am wanting to use the Docker network for the traffic between NGINX and Grafana and the name of the container is grafana on port 3000.

I currently have my NGINX default.conf as:

    server {
        listen 80;
        listen [::]:80;
        server_name localhost;
        return 301 https://$host$request_uri;
    }

    server {
        listen 443 ssl;
        server_name localhost;
        ssl_certificate                 /etc/ssl/certs/nginx-selfsigned.crt; # 
     or /etc/ssl/openhab.crt
        ssl_certificate_key             /etc/ssl/private/nginx-selfsigned.key; 
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers HIGH:!aNULL:!MD5;
        location / {
            proxy_pass http://grafana/;
        }
     }

It is not sending it to Grafana. It will switch HTTPS to HTTP but stops there. I am using another computer with an edited host file with mmig.com going to the IP address of this computer.

I can see http://mmig.com go to https://mmig.com and then it stops there. It won't take me to Grafana.

I get the error below when it is running.

nginx        | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
nginx        | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
nginx        | 10-listen-on-ipv6-by-default.sh: error: can not modify /etc/nginx/conf.d/default.conf (read-only file system?)
nginx        | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
nginx        | /docker-entrypoint.sh: Configuration complete; ready for start up
nginx        | 2020/09/11 17:26:59 [emerg] 1#1: host not found in upstream "grafana" in /etc/nginx/conf.d/default.conf:16
nginx        | nginx: [emerg] host not found in upstream "grafana" in /etc/nginx/conf.d/default.conf:16```


Docker-compose
``` grafana:
    image: grafana/grafana
    container_name: grafana
    restart: always
    depends_on:
     - influxdb
     - nginx
    ports:
     - "3000:3000"
    networks:
     - monitoring
    volumes:
      - grafana-db:/var/lib/grafana
      - grafana-log:/var/log/grafana
      - grafana-conf:/etc/grafana
      - ./certs:/etc/ssl:ro
  nginx:
   image: nginx
   container_name: nginx
   restart: always
   ports:
    - "80:80"
    - "443:443"
   networks:
    - monitoring
   volumes:
    - ./nginx/etc/nginx:/etc/nginx:ro
    - ./certs:/etc/ssl:ro
networks:
  monitoring:

nginx.conf

```
    user  nginx;
    worker_processes  1;

    error_log  /var/log/nginx/error.log warn;
    pid        /var/run/nginx.pid;


    events {
        worker_connections  1024;
    }


    http {
      include       /etc/nginx/mime.types;
      default_type  application/octet-stream;

      log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    upstream grafana {
        server grafana:3000;
    }

    include /etc/nginx/conf.d/*.conf;
    }
```

This is my current NGINX default.conf file where HTTP goes to HTTPS but it won't even go to the default NGINX home page. I haven't figured out why that is.

```   server {
        listen       80;
        server_name  localhost;
        return       301 https://$host$request_uri;
    }
    server {
        listen       443 ssl;
        server_name  localhost;
    # SSL
        ssl_certificate                 /etc/ssl/certs/nginx-selfsigned.crt; # 
     or /etc/ssl/openhab.crt
        ssl_certificate_key             /etc/ssl/private/nginx-selfsigned.key;

     location / {
            root   /usr/share/nginx/html;
        index  index.html index.htm;
        }
     }
```
1
It looks like the hostname 'grafana' is not resolving. Are the two containers part of a bridge network? docs.docker.com/network/bridge/… Are you using docker-compose to manage the two containers, or just individual docker commands?Nick ODell
Yes they are part of the monitoring network in Docker. I am also using docker-compose for this as well. Here is the output from Docker-Compose relating to these two containers.Gilbert PE
Can you post your docker-compose.yml? It might be relevant.Nick ODell
Ok I just added that to my question as well. If I don't have the HTTPS part in there it works just find handing it off to Grafana. Something is happening when I add the HTTPS in there. So HTTP to HTTPS works but not to Grafana and HTTP to Grafana reverse proxy works, but not HTTP-HTTPS-Grafana.Gilbert PE
More information that might help. I moved the upstream command to the nginx.conf file. It still isn't seeing it. 2020/09/11 18:05:20 [emerg] 1#1: host not found in upstream "grafana:3000" in /etc/nginx/nginx.conf:32 nginx: [emerg] host not found in upstream "grafana:3000" in /etc/nginx/nginx.conf:32 Gilbert PE

1 Answers

0
votes

It looks like since my host was on a Virtualbox VM and was behind a NAT since the bridge network was being used by another VM the proxy pass was being broken. I set up another computer with just this VM and it was able to use the bridge network and it worked just fine.