Need help for configuration with apache2 subdomain and subpath

  • What Grafana version and what operating system are you using?
  • Ubuntu 20.04.6 LTS
  • Grafana : 10.2.0

Note : _ are add in “url”

  • What are you trying to achieve?
    I try to setup grafana on a specific web (working) configuration on apache :

https_://sub.domain.com/ => an index page
https_://sub.domain.com/subpath1 => grafana
https_://sub.domain.com/subpath2 => other stuff

With tls redirection & websocket working.

And be sure my conf is valid.

ALL STUFF is behind F5 which i have no access. But error can come from that side too.
And the TLS is not currently fully setup (have a tls for domain.com i “accept” the risk).

  • How are you trying to achieve it?

Setup conf file (apache and grafana)

  • What happened?

Currently not working.

  • What did you expect to happen?
    A working configuration.

  • Can you copy/paste the configuration(s) that you are having problems with?

Directory structure :
/var/www/sub/webroot
/var/www/sub/subpath2
The apache conf :

<VirtualHost *:80>
  ServerName sub.domain.com
  DocumentRoot /var/www/sub/webroot

  RewriteEngine On
  RewriteCond %{REQUEST_URI} !^/\.well\-known/acme\-challenge/
  RewriteRule ^(.*)$ https_://%{HTTP_HOST}$1 [R=301,L]

  # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
  # error, crit, alert, emerg.
  # It is also possible to configure the loglevel for particular
  # modules, e.g.
  # LogLevel info ssl:warn
  LogLevel info

  ErrorLog ${APACHE_LOG_DIR}/error-sub.log
  CustomLog ${APACHE_LOG_DIR}/access-sub.log combined
</VirtualHost>

<VirtualHost *:443>
  ServerName sub.domain.com

  DocumentRoot /var/www/sub/webroot

  Alias /subpath2 /var/www/sub/subpath2/
  <Directory /var/www/sub/subpath2/>
     Options Indexes FollowSymLinks MultiViews
     Require all granted
   </Directory>

   <location "/sub/subpath1/" >
     ProxyPreserveHost On
     ProxyPass "http_://127.0.0.1:3000/"
     ProxyPassReverse "http_://127.0.0.1:3000/"
     RewriteEngine on
     RewriteCond %{HTTP:Upgrade} websocket [NC]
     RewriteCond %{HTTP:Connection} upgrade [NC]
     RewriteRule ^/?(.*) "ws://127.0.0.1:3000/$1" [P,L]
   </location>

    ErrorLog ${APACHE_LOG_DIR}/error-sub-ssl.log
    CustomLog ${APACHE_LOG_DIR}/access-sub-ssl.log combined

</VirtualHost>

The relevant part of my grafana.ini

[server]
protocol = http
http_addr =
http_port = 3000
domain = sub.domain.com
enforce_domain = false
root_url = %(protocol)s://%(domain)s/subpath1
serve_from_sub_path = true
  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.

Only 404 error or wrong redirection apache2 side. but i probably miss something.

  • Did you follow any online instructions? If so, what is the URL?
    Not remember exact url but mostly here and official documentation.

Nobody can help me ?

I found the solution myself.

I share here the “entire” solution.

The relevant apache2 conf file :

<VirtualHost *:80>
  ServerName sub.domain.com
  DocumentRoot /var/www/sub/webroot

   RewriteEngine On
   RewriteCond %{REQUEST_URI} !^/\.well\-known/acme\-challenge/
   RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]

   LogLevel info

    ErrorLog ${APACHE_LOG_DIR}/com/domain/sub/error-non-tsl.log
    CustomLog ${APACHE_LOG_DIR}/com/domain/sub/access-non-tsl.log combined
</VirtualHost>

<VirtualHost *:443>
    SSLEngine on
    SSLCertificateFile      /path/to/signed_cert_and_intermediate_certs
    SSLCertificateKeyFile   /path/to/private_key
    SSLCertificateChainFile /path/to/chain #not sure usefull

    # enable HTTP/2, if available
    Protocols h2 http/1.1

    # HTTP Strict Transport Security (mod_headers is required) (63072000 seconds)
    Header always set Strict-Transport-Security "max-age=63072000"

   ServerName sub.domain.com
   DocumentRoot /var/www/sub/webroot


   Alias /subpath2 /var/www/sub/subpath2/src
   <Directory /var/www/sub/subpath2/src>
     AllowOverride All
     Options Indexes FollowSymLinks MultiViews
     Require all granted
   </Directory>

   <Directory /var/www/sub/webroot>
        Options FollowSymLinks
        AllowOverride None
   </Directory>
   ReWriteEngine on

   <location "/subpath1/" >
     ProxyPreserveHost On
     ProxyPass "http://127.0.0.1:3000/subpath1/"
     ProxyPassReverse "http://127.0.0.1:3000/subpath1/"
     RewriteEngine on
     RewriteCond %{HTTP:Upgrade} websocket [NC]
     RewriteCond %{HTTP:Connection} upgrade [NC]
     RewriteRule ^/?(.*) "ws://127.0.0.1:3000/subpath1/$1" [P,L]
   </location>

    ErrorLog ${APACHE_LOG_DIR}/com/domain/sub/error.log
    CustomLog ${APACHE_LOG_DIR}/com/domain/sub/access.log combined

</VirtualHost>
# modern configuration
SSLProtocol             all -SSLv3 -TLSv1 -TLSv1.1 -TLSv1.2
SSLHonorCipherOrder     off
SSLSessionTickets       off

SSLUseStapling On
SSLStaplingCache "shmcb:logs/ssl_stapling(32768)"

The relevant grafana conf file :

instance_name =  sub.domain.com

[server]
protocol = http
http_addr =
http_port = 3000
domain = sub.domain.com
root_url = %(protocol)s://%(domain)s/subpath1/
serve_from_sub_path = true


For curious i extract grafana conf with :

cat /etc/grafana/grafana.ini | grep -v "^#\|;"  |less
# some blank space but good enough here 

I let that post open because i want to test further more. (real usage not only display a good url)

Feel free to kick my ass is you see some bad practices, wrong stuff and more.