Run librenms nginx on subdirectory

I was trying to make this work.

Was googling around and stumbled on this PR which was reverted :frowning:

Not sure if it’s something simple on nginx and config.php that can make this possible.

$config['base_url']        = "/librenms";

When configured with / and nginx.conf as here there no issues.

Is this even currently possible?
Any input would be appreciated.

Thanks!
dave

Works fine in Apache. Have you updated the nginx config as well as config.php?

Thank you for replying @laf

I’ve fiddled a bit with nginx but cant seem to make it work… not sure where i might be getting it wrong

	#location / {
	location /librenms {
		try_files $uri $uri/ @librenms;
	}
	#location ~ \.php {
	location ~ /librenms/*\.php {
		include fastcgi.conf;
		fastcgi_split_path_info ^(.+\.php)(/.+)$;
		fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
	}
	#location ~ /\.ht {
	location ~ /librenms/*\.ht {
		deny all;
	}
	location @librenms {
		#rewrite api/v0(.*)$ /api_v0.php/$1 last;
		rewrite api/v0(.*)$ /librenms/api_v0.php/$1 last;
		#rewrite ^(.+)$ /index.php/$1 last;
		rewrite ^(.+)$ /librenms/index.php/$1 last;
	}

Are you proxying to this web server from somewhere else first or just looking to run multiple things in one vhost?

Yes, im trying to proxy from somewhere else.

Our librenms server only has librenms and nginx. nginx only proxies the librenms application on root /

But from a reverse proxy (also nginx) how can i serve the librenms application?

We have several web applications and are able to serve them through said reverse proxy, if and only if they are in a subdirectory. I have issues when the web app is on root / (ie librenms)

Works fine accessing librenms directly:

https://librenms-lab/

but from the reverse proxy which should serve the above app

https://reverse-proxy/librenms  

Let me expound:

I was also trying to run librenms on a subdirectory and also trying to use a reverse proxy to access librenms

Basically you would be able to access librenms directly or through the reverse proxy.

BUT
At least with the success i’ve been having, i have been able to get some apps to work only when run on a subdirectory. So that’s why i was asking about running librenms on a subdirectory.

I know some users use a subdirectory, hopefully someone chimes in.

I personally use a sub domain, which is a much simpler config (assuming you can create the dns name).
librenms.mydomain.com for example.

I proxy from an nginx box to librenms on /librenms/ and don’t have to change my actual librenms install.

        location /librenms {
            proxy_pass http://librenms01/;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
        }

Then I have $config['base_url'] = '/librenms/'; set.

I don’t know if things changed from 2018, but no matter what I try librenms always redirects to the root. I have

$config['base_url']='/librenms'

in config.php

and

APP_URL=/librenms/

in .env, but:

curl -v -s -o /dev/null http://localhost:83
* Expire in 0 ms for 6 (transfer 0x55e0caba6e80)
* Expire in 1 ms for 1 (transfer 0x55e0caba6e80)
* Expire in 0 ms for 1 (transfer 0x55e0caba6e80)
* Expire in 1 ms for 1 (transfer 0x55e0caba6e80)
* Expire in 0 ms for 1 (transfer 0x55e0caba6e80)
* Expire in 0 ms for 1 (transfer 0x55e0caba6e80)
* Expire in 2 ms for 1 (transfer 0x55e0caba6e80)
* Expire in 0 ms for 1 (transfer 0x55e0caba6e80)
* Expire in 0 ms for 1 (transfer 0x55e0caba6e80)
* Expire in 2 ms for 1 (transfer 0x55e0caba6e80)
* Expire in 0 ms for 1 (transfer 0x55e0caba6e80)
* Expire in 0 ms for 1 (transfer 0x55e0caba6e80)
* Expire in 2 ms for 1 (transfer 0x55e0caba6e80)
* Expire in 0 ms for 1 (transfer 0x55e0caba6e80)
* Expire in 0 ms for 1 (transfer 0x55e0caba6e80)
* Expire in 2 ms for 1 (transfer 0x55e0caba6e80)
* Expire in 0 ms for 1 (transfer 0x55e0caba6e80)
* Expire in 0 ms for 1 (transfer 0x55e0caba6e80)
* Expire in 2 ms for 1 (transfer 0x55e0caba6e80)
* Expire in 1 ms for 1 (transfer 0x55e0caba6e80)
* Expire in 1 ms for 1 (transfer 0x55e0caba6e80)
* Expire in 1 ms for 1 (transfer 0x55e0caba6e80)
*   Trying ::1...
* TCP_NODELAY set
* Expire in 149998 ms for 3 (transfer 0x55e0caba6e80)
* Expire in 200 ms for 4 (transfer 0x55e0caba6e80)
* connect to ::1 port 83 failed: S’ha refusat la connexió
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Expire in 149998 ms for 3 (transfer 0x55e0caba6e80)
* Connected to localhost (127.0.0.1) port 83 (#0)
> GET / HTTP/1.1
> Host: localhost:83
> User-Agent: curl/7.64.0
> Accept: */*
> 
< HTTP/1.1 302 Found
< Server: nginx/1.14.2
< Content-Type: text/html; charset=UTF-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< Cache-Control: no-cache, private
< Date: Fri, 08 May 2020 08:13:14 GMT
< Location: https://localhost:83/login
< Set-Cookie: XSRF-TOKEN=eyJpdiI6IlF2cTJRNXdiZ25DeTV6T21sMGxWQnc9PSIsInZhbHVlIjoiUElGeG9vTEVuNnUxV0dIQ3JBY0tiSStCUDZKZ3ZjWUtyWFRsNWV0Y3dFQmo3bEY5UUFEVDJxcDZGVUxDY2JqRiIsIm1hYyI6ImU0MmQ2N2U4M2ZhN2JmOGNlOTU3MmQwZDFjNzI0NTVkMGU0MDBjZjJiMTVhZWNkNzk3YjNiODk0YWYzYjUzZDAifQ%3D%3D; expires=Fri, 08-May-2020 10:13:14 GMT; Max-Age=7200; path=/
< Set-Cookie: laravel_session=eyJpdiI6Ik9cL0RLMmEreDd1UGtRTTFqelVYeXhRPT0iLCJ2YWx1ZSI6IjU5MkpFVVByMHU2V3lkbTRxcUh1MXZlVEFpQ2RMdXl1Mk1RUUNKbGZUbVArWEdZd1F4QjBkeVRuNlwvcXJlZ0M2IiwibWFjIjoiZTgyYzNhNWRlODhkYmYzNTA3NGFkMjY5ODgyMTRhMWVkYjE0YTY3MDliMmY2MTNjMzg1MzNmNTkyNDA3YTcxMyJ9; expires=Fri, 08-May-2020 10:13:14 GMT; Max-Age=7200; path=/; httponly
< 
{ [362 bytes data]
* Connection #0 to host localhost left intact

nevermind, I finally put it in a subdomain

1 Like

so, now it impossible to use librenms with subdirectory?