How to use nginx to configure the first-level domain name to access the website and the second-level domain name to start as an express service?

the express project has been configured with pm2 on the server and can be started successfully. The node port of express is 3000
now you can see the data under the corresponding node api by visiting http://132.232.193.33:3000/about. My nginx currently looks like this:

server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    server_name  csdoker.com;
    root         /var/www/vue-blog-server/;

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

    location / {
        proxy_pass http://127.0.0.1:3000;
    }

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

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

this is only configured with the express project vue-blog-server. Now I want to configure a front-end project for vue-blog. How should I match it?
finally, the effect I want to achieve is to visit the first-level domain name csdoker.com and point to the vue-blog project index.html, access the second-level domain name api.csdoker.com/about to get the data of the express project

the current DNS record on Tencent Cloud reads as follows:

Does

also need to add a second-level domain name record, such as this?

  • Host record: api
  • record type: a
  • Line type: default
  • record value: 132.232.193.33

because you use a domain name system, this is relatively easier. You need to configure multiple host services in nginx to bind to different domain names, roughly

.
server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    -sharp 
    server_name  csdoker.com www.csdoker.com;
    root         /var/www/vue-blog/;

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

    location / {
        -sharp vue-blog4000root html
        proxy_pass http://127.0.0.1:4000;
    }

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

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }
}
server {
    listen       80;
    listen       [::]:80;
    -sharp 
    server_name  api.csdoker.com;
    root         /var/www/vue-blog-server/;

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

    location / {
        proxy_pass http://127.0.0.1:3000;
    }

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

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

for the domain name, you only need to set two a records, one for the first-level domain name and the other for the second-level domain name, both of which currently point to your service host.
in this way, nginx can automatically match according to the domain name accessed to provide different services
Note: if you directly use ip access (instead of domain name access), you will default to the first loaded listening on port 80

.

Domain name resolution is correct

nginx is configured as follows. Two server, are required because they are two domain names

-sharp 
server {
    listen 80;
    server_name csdoker.com;
     root         /var/www/vue-blog-server/;
    -sharp Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;
}
-sharp 
server {
    listen 80;
    server_name api.csdoker.com;
    location / {
        proxy_pass http://localhost:3000;
    }
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b35fdf-343a5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b35fdf-343a5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?