virepo
virepo

Reputation: 330

Setting up multiple domains on nginx server

I have one nginx server on ubuntu running a single application. I want let multiple domains point to this server.

Currently my /etc/nginx/sites-available/default looks like this:

(website1.com is just an example as I don't want to give out my real domain)

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


    root /var/www/website/public;
    index index.php index.html index.htm;


    server_name website1.com;

    location / {

            try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
            try_files $uri /index.php =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME 
            $document_root$fastcgi_script_name;
            include fastcgi_params;

    }

}

This works when someone going to website1.com

Now if people coming from website2.com do i just copy the code again exactly and change the server_name?

Or is there anything else I must do?

Upvotes: 2

Views: 6708

Answers (1)

Juan Sebastian
Juan Sebastian

Reputation: 1077

You can just list as many domain names on your server name directive

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


    root /var/www/website/public;
    index index.php index.html index.htm;


    server_name website1.com website2.com website3.com;
...

Bear in mind that you would need a dns that resolves website2.com to the same ip as website2.com also!

Upvotes: 6

Related Questions