Error setting up adminer with NGINX

September 3, 2019 88 views
Nginx Ubuntu 18.04

I have set up MeteorJs application with MongoDB backend. I am trying to set up adminer so I can query MongoDB without opening input ports on my droplet. Everytime I try to reload the nginx settings, I get nginx: [emerg] no port in upstream "php" in /etc/nginx/sites-enabled/admin:32 errors. What am I missing?

/etc/nginx/sites-enabled/admin

server {
    listen         80;
    server_name    165.227.197.220;
    return         301 https://$server_name$request_uri;
}

server {
    server_name    165.227.197.220;
    listen             443 ssl;
    access_log     /var/log/nginx/admin.access.log;
    error_log      /var/log/nginx/admin.error.log;

    ssl_certificate /etc/nginx/ssl/admin.crt;
    ssl_certificate_key /etc/nginx/ssl/admin.key;

    root           /var/www/admin;
    index          adminer.php;

    # Get file here https://codex.wordpress.org/Nginx
    include        global/restrictions.conf;

    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/.htpasswd/admin;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php;
        fastcgi_index adminer.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

/etc/nginx/global/restrictions.conf

# Global restrictions configuration file.
# Designed to be included in any server {} block.
location = /favicon.ico {
    log_not_found off;
    access_log off;
}

location = /robots.txt {
    allow all;
    log_not_found off;
    access_log off;
}

# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
# Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
location ~ /\. {
    deny all;
}

# Deny access to any files with a .php extension in the uploads directory
# Works in sub-directory installs and also in multisite network
# Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
location ~* /(?:uploads|files)/.*\.php$ {
    deny all;
}

2 Answers
bobbyiliev MOD September 3, 2019
Accepted Answer

Hello,

You have to change the fastcgi_pass php; part to your actual address of your FastCGI backend. The address can be specified as a TCP socket (IP and Port):

fastcgi_pass 127.0.0.1:9000;

or as a UNIX-domain socket path:


fastcgi_pass unix:/tmp/fastcgi.socket


Note that this would depend on your PHP FPM configuration. 

If you have not yet installed and configured PHP-FPM, I would recommend taking a look at stpe 3 here in this article:

https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-ubuntu-18-04

Hope that this helps!
Regards,
Bobby
by Justin Ellingwood
by Mark Drake
This tutorial details the process for installing and configuring the components that constitute a LEMP stack on an Ubuntu 18.04 server, including Nginx, MySQL, and PHP. It also includes instructions for testing that these components can communicate effectively and serve your content correctly.

Thank you Bobby, I am able to get the adminer login screen.

Here’s the changes that I made:
Installed universe and php-frm, php-mysql

sudo add-apt-repository universe
sudo apt install php-fpm php-mysql

Added the following node to the /etc/nginx/sites-enabled/admin file:

server {
    server_name    <MyDigitalOceanIpAddress>;
    listen         8081;
    root           /var/www/admin;
    index          adminer.php;
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    }
    location ~ /\.ht {
        deny all;
    }
}
edited by bobbyiliev
  • Hello,

    That’s great! I am happy to hear that you’ve managed to get it working and thank you for sharing this with the community!

    Regards,
    Bobby

Have another answer? Share your knowledge.