I finally have LibreNMS working reasonably well on a Debian 9 VM with Apache. It took me a while but I finally have it working on my domain via a sub-directory following the instructions for Sub-Directory.md. The good news is that LibreNMS is now working as expected from the following:
- 192.168.n.n/librenms
- domain[dot]com/librenms
The problem I am having is that attempting to navigate to the root web also brings up LibreNMS and navigation to other sub-folders on the site fail with a 404 error. For example,
- 192.168.n.n/ - also brings up LibreNMS
- domain[dot]com/ - also brings up LibreNMS
- 192.168.n.n/subsite - also brings up LibreNMS
- domain[dot]com/subsiste - also brings up LibreNMS
I believe all the redirects are being done in .htaccess but I do not understand how the redirects work. It seems like I am missing something either in the Apache configuration or something within the LibreNMS configuration is hijacking all site URL’s.
Any suggestions from the community? Many thanks in advance for any help.
Still looking for some help on this one. I’ve been doing more research and it looks like this has something to do with the .htaccess RewriteRules that I do not fully understand. From .htaccess:
RewriteEngine on
RewriteBase /librenms
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.(js|ico|txt|gif|jpg|png|css|php)
RewriteRule ^api/v0(.)$ api_v0.php/$1
RewriteCond %{REQUEST_URI} !=/server-status
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.(js|ico|txt|gif|jpg|png|css|php)
RewriteRule ^(.)$ index.php
If I am following and understanding this correctly, it looks like the last rule, “RewriteRule ^(.*)$ index.php”, seems to be to direct any other requests that don’t match the previous ones to LibreNMS index.php.
I’m sure folks have installed LibreNMS on a single web host that hosts sub-sites. I haven’t found the magic answer yet.
Whats your apache config?
Thanks for the response! I think I am supposed to attach a file but I can’t find the post with the instructions. Hopefully this works. I’ve removed most of the comments out of my apache2.conf file and here is the contents. Thank you for your willingness to review.
Global configuration
USER ADDED DIRECTIVES
ServerTokens Prod
ServerSignature Off
The directory where shm and other runtime files will be stored.
DefaultRuntimeDir ${APACHE_RUN_DIR}
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
These need to be set in /etc/apache2/envvars
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
Include module configuration:
IncludeOptional mods-enabled/.load
IncludeOptional mods-enabled/.conf
Include list of ports to listen on
Include ports.conf
Sets the default security model of the Apache2 HTTPD server. It does
not allow access to the root filesystem outside of /usr/share and /var/www.
The former is used by web applications packaged in Debian,
the latter may be used for local directories served by the web server. If
your system is serving content from a sub-directory in /srv you must allow
access here, or in any related virtual host.
Options FollowSymLinks
AllowOverride None
Require all denied
<Directory /usr/share>
AllowOverride None
Require all granted
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
AccessFileName: The name of the file to look for in each directory
for additional configuration directives. See also the AllowOverride
directive.
AccessFileName .htaccess
The following lines prevent .htaccess and .htpasswd files from being
viewed by Web clients.
<FilesMatch “^.ht”>
Require all denied
LogFormat “%v:%p %h %l %u %t "%r" %>s %O "%{Referer}i" "%{User-Agent}i"” vhost_combined
LogFormat “%h %l %u %t "%r" %>s %O "%{Referer}i" "%{User-Agent}i"” combined
LogFormat “%h %l %u %t "%r" %>s %O” common
LogFormat “%{Referer}i → %U” referer
LogFormat “%{User-agent}i” agent
Include of directories ignores editors’ and dpkg’s backup files,
see README.Debian for details.
Include generic snippets of statements
IncludeOptional conf-enabled/*.conf
Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf
Do you have librenms under /var/www/librenms or where?
librenms is installed at /opt/librenms per the installation instructions. Here is the librenms conf info.
<VirtualHost 192.168.2.194:80>
DocumentRoot /opt/librenms/html/
AllowEncodedSlashes On
Alias /librenms /opt/librenms/html
<Directory “/opt/librenms/html”>
Require all granted
AllowOverride All
Options FollowSymLinks MultiViews
Ok then you dont have a sub-folder install, you have a direct virtual domain install, then is totally normal that all pages redirect you to librenms, as your server is only serving librenms.
Hmmm. I’m not sure I understand that. What I am trying to accomplish is having a single Apache server serve 4 web sites.
- / root site - Simply a landing page
- /librenms - LibreNMS network management console
- /wp - Wordpress site
4 /zp - Zenphoto site
My understanding is that if I create conf files for each site in sites-available, I can have each sub-dir direct the virtual host to each respective folder.
What is currently happening is that regardless of which URL I go to, all bring up Librenms.
/, /wp, /zp, /librenms all will serve librenms. Each site has its own document root and alias.
Your virtualhost without servername directive (you have it commented) means all request will go to that virtualhost, making /opt/librenms/html the root directory for all.
You have 2 options:
A) Fully move to virtual host domains
That means having a sub domain for each one, then configure a virtualhost for each with different ServerName directive (librenms.yourdomain, wp.yourdomain, zp.yourdomain,etc…)
B) Set the documentroot directive to /var/www then make a symbolic link from /var/www/librenms to /opt/librenms/html (never used this one so not really sure if you have to do anything else)
Thank you for the additional clarification. It now makes sense to me. In my scenario, I only have one host and want to host several sites in sub-folders. With your clarification I made the following changes and all appears to be working now.
- Edit apache2.conf to include the <“Directory”> directive from librenms.conf.
- Removed librenms.conf from available-sites folder.
- Validated apache2 config and restarted apache2.
Now everything is working as I expect.
Thank you again for setting me straight.