Two domains on the same Nginx server

April 14, 2015 560 views
Nginx WordPress

Hi, I have one site already set up on Nginx and tried to add a second but is not working.

Every time I try to access the second field I am directed to the first domain. What might be happening?

site1 = inforlogia.com
site2 = tudodesconto.com

config for site1:

server {
    listen 80 default_server;
    error_log /var/www/error.log;
    access_log off;
    root /var/www/inforlogia.com;
    server_name inforlogia.com;
    index index.php;
    include /etc/nginx/wordpress.conf;
}

config for site2:

server {
    listen 80;
    listen [::]:80;
    error_log /var/www/error.tudodesconto.log;
    access_log off;
    root /var/www/tudodesconto.com;
    server_name tudodesconto.com;
    index index.php;
    include /etc/nginx/wordpress.conf;

}

wordpress.conf

 location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;

        }

    location / {
    try_files $uri $uri/ /index.html;
    rewrite ^/sitemap_index\.xml$ /index.php?sitemap=1 last;
    rewrite ^/([^/]+?)-sitemap([0-9]+)?\.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
    }

    location ~ \.conf$ {
    deny all;
    }

    if (!-e $request_filename)
    {
    rewrite ^(.+)$ /index.php?q=$1 last;
    }
2 Answers

I solved the problem. I changed (each block):

server {
    server_name inforlogia.com;
......

}

to

server {
    server_name inforlogia.com www.inforlogia.com;
......

}

I spent two days on it ...

Have another answer? Share your knowledge.