Installing LibreNMS on Ubuntu 20.04 with NGINX, getting "502 Bad Gateway" in the Web Installer step

Hi,

I’m trying to install LibreNMS on a freshly installed Ubuntu 20.04 server, with all the updates.
After following the installation instructions carefully (https://docs.librenms.org/Installation/Install-LibreNMS/), with the Ubuntu 20.04 and NGINX options, I’m getting “502 Bad Gateway” error in the ‘Web installer’ section.

There is nothing in the ‘/etc/nginx/sites-enabled/’ directory, and in the ‘/etc/nginx/sites-available’ directory the only file is ‘default’.

Seems like some steps are missing from the ‘Configure Web Server’ section in the installation guide.

Any help how to fix?

Thanks

Good morning. Someone had a similar issue not long ago…It looks like you may have missed a few steps:
In /etc/php/7.4/fpm/pool.d - do you have a librenms.conf file? If not, do the following.

cp /etc/php/7.4/fpm/pool.d/www.conf /etc/php/7.4/fpm/pool.d/librenms.conf
vi /etc/php/7.4/fpm/pool.d/librenms.conf

CentOS 8 Debian 10

# Change "www" to "librenms"
[librenms]

# Change user and group to "librenms"
user = librenms
group = librenms

# Change listen to a unique name
listen = /run/php-fpm-librenms.sock

next, do the configuration for the web server:

vi /etc/nginx/conf.d/librenms.conf
```server {
 listen      80;
 server_name librenms.example.com;
 root        /opt/librenms/html;
 index       index.php;

 charset utf-8;
 gzip on;
 gzip_types text/css application/javascript text/javascript application/x-javascript image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
 location / {
  try_files $uri $uri/ /index.php?$query_string;
 }
 location ~ [^/]\.php(/|$) {
  fastcgi_pass unix:/run/php-fpm-librenms.sock;
  fastcgi_split_path_info ^(.+\.php)(/.+)$;
  include fastcgi.conf;
 }
 location ~ /\.(?!well-known).* {
  deny all;
 }
}

rm /etc/nginx/sites-enabled/default
systemctl restart nginx
systemctl restart php7.4-fpm

Hi, thanks for answering.

I did all that:

[email protected]:~# cat /etc/php/7.4/fpm/pool.d/librenms.conf
; Start a new pool named ‘www’.
; the variable $pool can be used in any directive and will be replaced by the
; pool name (‘www’ here)
[librenms]
; Per pool prefix
; It only applies on the following directives:
; - ‘access.log’
; - ‘slowlog’
; - ‘listen’ (unixsocket)
; - ‘chroot’
; - ‘chdir’
; - ‘php_values’
; - ‘php_admin_values’
; When not set, the global prefix (or /usr) applies instead.
; Note: This directive can also be relative to the global prefix.
; Default Value: none
;prefix = /path/to/pools/$pool
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user’s group
; will be used.
user = librenms
group = librenms
; The address on which to accept FastCGI requests.
; Valid syntaxes are:
; ‘ip.add.re.ss:port’ - to listen on a TCP socket to a specific IPv4 address on
; a specific port;
; ‘[ip:6:addr:ess]:port’ - to listen on a TCP socket to a specific IPv6 address on
; a specific port;
; ‘port’ - to listen on a TCP socket to all addresses
; (IPv6 and IPv4-mapped) on a specific port;
; ‘/path/to/unix/socket’ - to listen on a unix socket.
; Note: This value is mandatory.
listen = /run/php/php-fpm-librenms.sock

and:

[email protected]:~# cat /etc/nginx/conf.d/librenms.conf
server {
listen 80;
server_name aragorn.local.lan;
root /opt/librenms/html;
index index.php;

charset utf-8;
gzip on;
gzip_types text/css application/javascript text/javascript application/x-javascript image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ [^/].php(/|$) {
fastcgi_pass unix:/run/php-fpm-librenms.sock;
fastcgi_split_path_info ^(.+.php)(/.+)$;
include fastcgi.conf;
}
location ~ /.(?!well-known).* {
deny all;
}
}

But I’m still getting:

502 Bad Gateway
nginx/1.18.0 (Ubuntu)

Interesting…the ubuntu / debian instructions are different…even though ubuntu is based on Debian.
Odd stuff. I genuinely don’t know enough about that to comment on it.

Perhaps try:

vi /etc/nginx/sites-enabled/librenms.vhost

Add the following config, edit server_name as required:

server {
 listen      80;
 server_name librenms.example.com;
 root        /opt/librenms/html;
 index       index.php;

 charset utf-8;
 gzip on;
 gzip_types text/css application/javascript text/javascript application/x-javascript image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
 location / {
  try_files $uri $uri/ /index.php?$query_string;
 }
 location ~ [^/]\.php(/|$) {
  fastcgi_pass unix:/run/php-fpm-librenms.sock;
  fastcgi_split_path_info ^(.+\.php)(/.+)$;
  include fastcgi.conf;
 }
 location ~ /\.(?!well-known).* {
  deny all;
 }
}
rm /etc/nginx/sites-enabled/default
systemctl reload nginx
systemctl restart php7.3-fpm

With the vhost file now in sites-enabled directory, I’m still getting:

502 Bad Gateway
nginx/1.18.0 (Ubuntu)

Also tried to restart the server, but no help :frowning:

here’s a similar recent thread - maybe there’s something in here that’s worth looking at:

also, might be worth creating a phpinfo.php file and drop that in your web directory and see if your server will serve it up. can also do the same with just a “test.htm” file just testing and see if you can browse to that. That would tell us if the web server is serving correctly, whether there’s a problem with PHP or not and whether there’s a problem with librenms.

Hi, I had the same problem and solved with this change in /etc/php/7.4/fpm/pool.d/librenms.conf file:

user = librenms
group = librenms
listen = /run/php/php-fpm-librenms.sock
;listen = /run/php/php7.4-fpm.sock

; Set listen(2) backlog.
; Default Value: 511 (-1 on FreeBSD and OpenBSD)
;listen.backlog = 511

; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server. Many
; BSD-derived systems allow connections regardless of permissions.
; Default Values: user and group are set as the running user
; mode is set to 0660

listen.owner = www-data
listen.group = www-data
;listen.mode = 0660

Also in /etc/nginx/conf.d/librenms.conf change line 14 into this:

fastcgi_pass unix:/run/php/php-fpm-librenms.sock;

Restart both services and it should work.

2 Likes

Having similar issues, and have not found a resolution, any help would be greatly appreciated,.

502 Bad Gateway

nginx/1.17.10 (Ubuntu 18.04)

validate.php output -
$ ./validate.php

Component Version
LibreNMS 1.70.1-1-ga3635d0b7
DB Schema 2020_10_12_095504_mempools_add_oids (191)
PHP 7.4.13
Python 3.6.9
MySQL 10.1.47-MariaDB-0ubuntu0.18.04.1
RRDTool 1.7.0
SNMP NET-SNMP 5.7.3

====================================

[OK] Composer Version: 2.0.8
[OK] Dependencies up-to-date.
[OK] Database connection successful
[OK] Database schema correct

daily.sh output -
$ ./daily.sh
Updating to latest codebase OK
Updating Composer packages OK
Updating SQL-Schema OK
Updating submodules OK
Cleaning up DB OK
Fetching notifications OK
Caching PeeringDB data

PROBLEM SOLVED, as it turns out, I had a typo in my php-fpm.d/www.conf

Listen = /run/php/php-fpm-librenms.sock

Thanks.

1 Like

this sorted my issue as well. thx for sharing

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.