Accessing phpmyadmin in Nginx directly from IP address (without a subdomain)

In an Ubuntu 16.04 Nginx environment which has some sites working fine, I've installed phpmyadmin:

cd /var/www/html
wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.zip
find ./ -type f -iname '*phpmyadmin*.zip' -exec unzip {} \;
find ./ -type d -iname 'phpmyadmin-*' -exec mv {} phpmyadmin \;

I then tried to access it from my browser via ip_address/phpmyadmin, yet I got a 404 in one of my sites.

I thought this is caused from lacking a webapp conf so I created one.

nano /etc/nginx/sites-available/phpmyadmin.conf:

server {
    root /var/www/html/phpmyadmin/;
    server_name phpmyadmin;

    location / {
        index index.php index.html index.htm fastcgi_index;
        try_files $uri $uri =404 $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    listen 80;
}

Then

ln -s /etc/nginx/sites-available/phpmyadmin.conf /etc/nginx/sites-enabled/
systemctl restart nginx.service

Yet, the problem persist.

The logs specify only this error:

2018/01/01 03:02:25 [emerg] 21959#21959: unknown directive "/var/www/html/phpmyadmin/" in /etc/nginx/sites-enabled/phpmyadmin.conf:2

I basically didn't change nginx.conf and rely on its native directives.

I have consulted an Nginx sysadmin how suggested me to use a subdomain but I prefer accessing it directly from IP address.


The server_name should contain the name(s) used to access the server. To access a server by IP address, it should contain the IP address.

For example:

server_name 192.0.2.1;

See this document for more.

But first you need to fix that error - I don't know why you are getting an unknown directive error from your root statement. Have you introduced a typo?