2

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?

1 Answer 1

6

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!

Sign up to request clarification or add additional context in comments.

3 Comments

thanks dude! what would i do when it comes to ssl certs ?
if you are using subdomains you can just use wildcard certs, but if your sites are like website1.com and website2.com instead of web2.website.com and web1.website.com you would need to have a server block for each site with pretty much the same thing, just changing the server_name and ssl parts.
please accept the answer if it meets your expectations :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.