Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different Domains on Different IP's in Nginx?

Tags:

nginx

I want to use two different domains with different IP addresses, for example

domain1.com - 12.34.56.78 
domain2.com - 98.76.54.32

I am using nginx on Linux OS. What should I add in my nginx.conf?

like image 840
Vineet Sharma Avatar asked Jan 17 '23 02:01

Vineet Sharma


1 Answers

You have to create two virtual hosts using server block.

Let's suppose /var/www contains domain1.com and domain2.com directories with whatever HTML pages, CGI scripts, ...

server {
  listen          12.34.56.78:80;
  server_name     domain1.com

  index           index.html;
  root            /var/www/domain1.com
}

server {
  listen          98.76.54.32:80;
  server_name     domain2.com;

  index           index.html;
  root            /var/www/domain2.com
}
like image 175
dave Avatar answered Feb 04 '23 02:02

dave