在Nginx配置文件中,可以通过添加两个server块来增加两个HTTP服务器。以下是一个示例配置文件:

http {
    server {
        listen 80;
        server_name example.com;

        location / {
            root /var/www/example.com;
            index index.html;
        }
    }

    server {
        listen 80;
        server_name test.example.com;

        location / {
            root /var/www/test.example.com;
            index index.html;
        }
    }
}

在上面的示例中,我们定义了两个server块。第一个server块监听端口80,并使用example.com作为主机名。它的根目录是/var/www/example.com,并指定了默认的索引文件为index.html。第二个server块同样监听端口80,但使用test.example.com作为主机名,并使用不同的根目录/var/www/test.example.com

请根据您的需求修改主机名、根目录和其他配置参数。完成后,重启Nginx以使配置生效。

nginx http下增加两个server

原文地址: https://www.cveoy.top/t/topic/i8Jg 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录