Question

Multiple sites using nginx

  • Posted July 20, 2014

I was able to set up nginx server blocks as per this tutorial. When I try to access the sites through the respective domain names I am directed to the same site. I’m not sure if this is an nginx issue or a dns issue.

Subscribe
Share

I have two files:

One:

server {
	listen 80;
	listen [::]:80 default_server ipv6only=on;

	root /var/www/munderground.com/public_html;
	index index.html index.htm;

	# Make site accessible from http://localhost/
	server_name munderground.com www.munderground.com;

	location / {
		# First attempt to serve request as file, then
		# as directory, then fall back to displaying a 404.
		try_files $uri $uri/ /index.html;
		# Uncomment to enable naxsi on this location
		# include /etc/nginx/naxsi.rules
	}

	location /doc/ {
		alias /usr/share/doc/;
		autoindex on;
		allow 127.0.0.1;
		allow ::1;
		deny all;
	}

Two:

server {
	listen 80;
	listen [::]:80;

	root /var/www/verred.com/public_html;
	index index.html index.htm;

	# Make site accessible from http://localhost/
	server_name verred.com www.verred.com;

	location / {
		# First attempt to serve request as file, then
		# as directory, then fall back to displaying a 404.
		try_files $uri $uri/ /index.html;
		# Uncomment to enable naxsi on this location
		# include /etc/nginx/naxsi.rules
	}

	location /doc/ {
		alias /usr/share/doc/;
		autoindex on;
		allow 127.0.0.1;
		allow ::1;
		deny all;
	}

Paste your Vhost(s) from nginx.


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

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.

remove [ default_server ipv6only=on ] in the listen property in the server 2 file. Only one block should be designated as default_server.

Correct configuration: Block one:

server { listen 80; listen [::]:80 default_server ipv6only=on;

Block two:

server { listen 80; listen [::]:80;

Hi!

I see different content on each of those domains, so it looks like you got it working! It would be great if you could share what the root cause of your issue was and how you fixed it. That would help others who end up at this question.

Your configuration files look correct. One thing many people forget is that you need to restart Nginx after making any changes:

sudo service nginx restart

Hi!

I see different content on each of those domains, so it looks like you got it working! It would be great if you could share what the root cause of your issue was and how you fixed it. That would help others who end up at this question.

Your configuration files look correct. One thing many people forget is that you need to restart Nginx after making any changes:

sudo service nginx restart

Hi!

I see different content on each of those domains, so it looks like you got it working! It would be great if you could share what the root cause of your issue was and how you fixed it. That would help others who end up at this question.

Your configuration files look correct. One thing many people forget is that you need to restart Nginx after making any changes:

sudo service nginx restart

Hi!

I see different content on each of those domains, so it looks like you got it working! It would be great if you could share what the root cause of your issue was and how you fixed it. That would help others who end up at this question.

Your configuration files look correct. One thing many people forget is that you need to restart Nginx after making any changes:

sudo service nginx restart

I have server with IP I dont have domain name I want to host two seporate appliaction. I need Help.

I have the same question; I have multiple domains redirecting to the same nginx server, but my PHP code handles each site differently.

When I have set up the one domain to point at my servers IP, I simply see the old site.

Any solutions on this? Is it simply to remove ipv6only=on?