Multiple Wordpress sites on single droplet with NGINX - problem with Server Block

January 17, 2018 758 views
WordPress Nginx Ubuntu 16.04

I have two Wordpress sites installed, example.com and test.com.
Server is Nginx.
I configured my local /etc/hosts so that example.com, www.example.com, test.com and www.test.com - all point to the ip address of my VPS.
It works, but only partially.
The URL http://test.com works as expected, and I see the correct Wordpress site.
However, http://example.com sends me to the page directed by the default Server Block, and that's not what I want.

Thank you for taking the time to read my question and working to help me.

For the reference, here are the 3 Server Blocks I have: default, example.com and test.com.

# default
server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html;

    index index.php index.html index.htm index.nginx-debian.html;

    server_name 207.154.250.232;

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

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;  
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
}
# example.com
server {
    listen 80;
    listen [::]:80;

    root /var/www/example.com/html;

    index index.php index.html index.htm index.nginx-debian.html;

    server_name example.com www.example.com;

    location / {
                try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;

        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
        location = /favicon.ico { log_not_found off; access_log off; }
        location = /robots.txt { log_not_found off; access_log off; allow all; }
        location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
            expires max;
            log_not_found off;
        }
}
# test.com
server {
    listen 80;
    listen [::]:80;

    root /var/www/test.com/html;

    index index.php index.html index.htm index.nginx-debian.html;

    server_name test.com www.test.com;

    location / {
                try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;

        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
        location = /favicon.ico { log_not_found off; access_log off; }
        location = /robots.txt { log_not_found off; access_log off; allow all; }
        location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
            expires max;
            log_not_found off;
        }
}

Be the first one to answer this question.