如何使用nginx创建子域并将API映射到localhost:80?

How use nginx to create subdomains and map API to localhost:80?

我有一个 docker 运行 我的 api localhost:80 和我的 [=25= 的 2 个文件夹]战线.

这是我想要的:

如何做到这一点?

我从@Patrick-Mevzek 那里找到了答案并表示感谢。

我通过将以下服务器块添加到我的 nginx 配置中解决了我的问题。

server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    root         /home/erfantahvieh.com/front;

    server_name domain.example www.domain.example;                

    index index.html index.htm index.nginx-debian.html;

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location / {
         autoindex on;
         autoindex_exact_size off;
    }

    error_page 404 /404.html;
            location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
            location = /50x.html {
    }
}

server {
    listen       80;
    root         /home/erfantahvieh.com/admin;

    server_name admin.domain.example www.admin.domain.example;                

    index index.html index.htm index.nginx-debian.html;

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location / {
    }

    error_page 404 /404.html;
            location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
            location = /50x.html {
    }
}

server {
    listen       80;
    root         /usr/share/nginx/html;

    server_name api.domain.example www.api.domain.example;                

    index index.html index.htm index.nginx-debian.html;

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location / {
            proxy_pass http://xxx.xxx.xxx.xxx:8080/;
    }
}