在nginx服务器上设置多个域

时间:2017-09-01 12:20:43

标签: nginx configuration

我在ubuntu上有一个运行单个应用程序的nginx服务器。我想让多个域指向此服务器。

目前我的/ etc / nginx / sites-available / default看起来像这样:

(website1.com只是一个例子,因为我不想透露我的真实域名)

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;

    }

}

当有人访问website1.com

时,这是有效的

现在,如果来自website2.com的人我是否只是再次复制代码并更改server_name?

或者我还有什么必须做的吗?

1 个答案:

答案 0 :(得分:1)

您可以在服务器名称指令

上列出尽可能多的域名
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;
...

请记住,您还需要一个将website2.com解析为与website2.com相同的网址的DNS!

相关问题