在 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/lF9G 著作权归作者所有。请勿转载和采集!

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