Question

Two domains on the same Nginx server

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;
	}

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

This comment has been deleted

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 …