Grafana and Nginx in Docker. Connection problem

Hello. I am trying to set up an environment for grafana and nginx, but getting 502 Bad Request from Nginx. Tried many configs and read a lot of forums, nothing helped so far. My configs:
docker-compose:
version: “3”

networks:
test:
ipam:
config:
- subnet: 10.0.1.0/16

services:
nginx:
image: nginx
container_name: nginx
restart: unless-stopped
tty: true
ports:
- “80:80”
- “443:443”
volumes:
- ./nginx/ngconf:/etc/nginx/conf.d:ro
networks:
test:
ipv4_address: 10.0.1.2

grafana:
image: grafana/grafana-oss
container_name: grafana
restart: unless-stopped
environment:
- GF_SERVER_DOMAIN=https:// dev01
- GF_SERVER_ROOT_URL=https:// dev01/grafana/
- GF_SERVER_SERVE_FROM_SUB_PATH=true
- GF_INSTALL_PLUGINS=grafana-clock-panel
ports:
- ‘3000:3000’
networks:
test:
ipv4_address: 10.0.1.3

nginx.conf:
map $http_upgrade $connection_upgrade {
default upgrade;
‘’ close;
}

upstream grafana {
server grafana:3000;
}

server {
listen 80;
root /usr/share/nginx/www;
index index.html index.htm;
server_name dev01;

return 301 https://$host$request_uri;
}

server {
listen 443 ssl;
server_name dev01;

ssl_certificate /etc/nginx/conf.d/dev01.pem;
ssl_certificate_key /etc/nginx/conf.d/dev01.key;

location /grafana/ {
rewrite ^/grafana/(.*) /$1 break;
proxy_set_header Host $http_host;
proxy_pass http://grafana;
}

location /grafana/api/live/ {
rewrite ^/grafana/(.*) /$1 break;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $http_host;
proxy_pass http:// grafana;
}

}

please, any advice will be highly appreciated, what is wrong with my configs. Thank you
P.S. I put space in the links since editor disallow more than 2 links in a post

Made it working. For some reasons, it works only with this configuration:
environment:

  • GF_SERVER_DOMAIN=https:// dev01/grafana/
  • GF_SERVER_ROOT_URL=https:// dev01/grafana/
  • GF_INSTALL_PLUGINS=grafana-clock-panel

So, GF_SERVER_DOMAIN and GF_SERVER_ROOT_URL are the same, with subpath inclided. And GF_SERVER_SERVE_FROM_SUB_PATH I removed. I don’t know, honestly, why it’s like that consider in the documentation it vise versa.