title: Reverse Proxy (nginx) with Grafana
body: <p>I have followed the instructions provided by Grafana (<a href="https://grafana.com/tutorials/run-grafana-behind-a-proxy/#1" rel="nofollow noreferrer">https://grafana.com/tutorials/run-grafana-behind-a-proxy/#1</a>), but continue to not be successful. Below is my nginx config file. The problem is when I go to <a href="http://www.example.com/grafana" rel="nofollow noreferrer">http://www.example.com/grafana</a> it redirects me to <a href="http://www.example.com/login" rel="nofollow noreferrer">www.example.com/login</a> which returns 404. Thank you for any assistance!</p>
  <p>NGINX Configuration File</p>
  <pre><code>server {
      listen       80;
      listen  [::]:80;
      server_name  localhost;
  
      location / {
          root   /usr/share/nginx/html;
          index  index.html index.htm;
      }
  
      #error_page  404              /404.html;
  
      # redirect server error pages to the static page /50x.html
      error_page   500 502 503 504  /50x.html;
      location = /50x.html {
          root   /usr/share/nginx/html;
      }
  
      # Portainer
      location /portainer/ {
        proxy_http_version 1.1;
        proxy_set_header Connection &quot;&quot;;
        proxy_pass http://www.example.com:9000/;
      }
      location /portainer/ws/ {
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection &quot;upgrade&quot;;
        proxy_http_version 1.1;
        proxy_pass http://www.example.com:9000/ws/;
      }
  
      # Grafana
      location /grafana/ {
          proxy_pass   http://www.example.com:3000/;
      }
  }
  </code></pre>
  <p>Grafana Configuration File</p>
  <pre><code>#################################### Server ####################################
  [server]
  # Protocol (http, https, h2, socket)
  ;protocol = http
  
  # The ip address to bind to, empty will bind to all interfaces
  ;http_addr =
  
  # The http port  to use
  ;http_port = 3000
  
  # The public facing domain name used to access grafana from a browser
  ;domain = example.com
  
  # Redirect to correct domain if host header does not match domain
  # Prevents DNS rebinding attacks
  ;enforce_domain = false
  
  # The full public facing url you use in browser, used for redirects and emails
  # If you use reverse proxy and sub path specify full url (with sub path)
  ;root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana/
  
  # Serve Grafana from subpath specified in `root_url` setting. By default it is set to `false` for compatibility reasons.
  ;serve_from_sub_path = true
  
  # Log web requests
  ;router_logging = false
  
  # the path relative working path
  ;static_root_path = public
  
  # enable gzip
  ;enable_gzip = false
  
  # https certs  key file
  ;cert_file =
  ;cert_key =
  
  # Unix socket path
  ;socket =
  </code></pre>