使 nginx 配置类似 apache2 虚拟主机

使 nginx 配置类似 apache2 虚拟主机

我有一个安装了 apache2 的 Web 服务器,上面有许多子域名,比如 domain.com、abc.domain.com、def.domain.com 等等。现在我有了一个新的 nginx 服务器,想像 apache2 一样设置它,因此为了测试,我创建了配置(/etc/nginx/sites-available/ 中的 2 个文件,并从 sites-enabled/ 链接到它们),如下所示,

域名.config:

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        root /srv/www/;
        index index.html index.htm;

        # Make site accessible from http://localhost/
        server_name domain.com;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }
}

abc 域配置:

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

        root /srv/www/tmp1/;
        index index.html index.htm;

        # Make site accessible from http://localhost/
        server_name abc.domain.com;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }
}

但是当我使用 domain.com 访问时,我只能从 /var/www/tmp1 获取 index.html。我在 nginx 配置中做错了什么吗?

相关内容