0

I've asked on the forums before but didn't get answer so I'm going to try again.

I'm trying to setup NGINX with PHPMyAdmin and I want to access the site via two subdomains and an IP address. The following URLs all lead to the same root folder:-

  • phpmyadmin.localhost (only accessible via the host machine)
  • phpmyadmin.ubuntu-pc.lan (accessible via other LAN machines)
  • 192.168.0.123/phpmyadmin (accessible via other LAN machines)

This is my current server block

# PHPMyAdmin
#
server {
    listen 80;
    listen [::]:80;
    #listen 443 ssl;
    #listen [::]:443 ssl;

    root /var/www/html/phpmyadmin;
    index index.php index.html index.htm index.nginx-debian.html;

    server_name 192.168.1.123 phpmyadmin.localhost phpmyadmin.ubuntu-pc.lan;

    location / {
        try_files $uri $uri/ $uri/index.php =404;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

Could someone tell me how I achieve this?

UPDATE

The problem I have is when accessing the Ubuntu machine from another device on the LAN I'm unable to access the IP address with the trailing directory 192.168.xxx.xxx/phpmyadmin or the subdomain phpmyadmin.ubuntu-pc.lan.

Instead they're both accessible without the trailing directory and subdomain.

willowen100
  • 31
  • 2
  • 10

1 Answers1

0

You need to have separate server blocks for your config.

server {
    listen 127.0.0.1:80;

    server_name phpmyadmin.localhost;

    ...
}

server {
    listen 192.168.1.123:80;

    server_name 192.168.1.123 phpmyadmin.ubuntu-pc.lan;

    ...
}
Tero Kilkanen
  • 36,796
  • 3
  • 41
  • 63