Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx Different Domains on Same IP

Tags:

nginx

dns

People also ask

Can I have 2 domains on the same IP?

It is not possible to provide two domain names for the same Server IP address and get two different SSL certificates (one for each domain name). Also note that the use of Host Headers (which is how you can use a single IP for more than one SSL enabled domain) is not recommended for E-Commerce sites.

Can NGINX host multiple domains?

NGINX allows you to host multiple websites on a single server with the help of virtual hosts. Each virtual host handles a website domain and serves requests from its own Document Root folder.


Your "listen" directives are wrong. See this page: http://nginx.org/en/docs/http/server_names.html.

They should be

server {
    listen      80;
    server_name www.domain1.com;
    root /var/www/domain1;
}

server {
    listen       80;
    server_name www.domain2.com;
    root /var/www/domain2;
}

Note, I have only included the relevant lines. Everything else looked okay but I just deleted it for clarity. To test it you might want to try serving a text file from each server first before actually serving php. That's why I left the 'root' directive in there.