How to specify the root address for express?

Launched express server on 127.0.0.1:3000 and proxenou it in nginx
sites-enabled/default
map $sent_http_content_type $expires {
 "text/html" epoch;
 "text/html; charset=utf-8" epoch;
 default off;
}

server {
 listen 80;
 access_log /var/log/nginx/access.log;
 return 301 https://$host$request_uri; 
 server_name site.ru www.site.ru; # setup your domain here
 root /root/site;

 gzip on;
 gzip_types text/plain application/xml text/css application/javascript;
 gzip_min_length 1000;

 location / {
 expires $expires;

 "proxy_redirect" off;
 proxy_set_header Host $Host;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_set_header X-Forwarded-Proto $scheme;
 proxy_read_timeout 1m;
 proxy_connect_timeout 1m;
 proxy_pass http://127.0.0.1:3001; # set the adress of the Node.js instance here
}

 location /api/ {
 "proxy_redirect" off;
 proxy_set_header Host $Host;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_set_header X-Forwarded-Proto $scheme;
 proxy_read_timeout 1m;
 proxy_connect_timeout 1m;
 proxy_pass https://127.0.0.1:3000;
}
}

server {
 listen 443 ssl;
 listen [::]:443 ssl;
 access_log /var/log/nginx/access.log; 
 ssl_certificate /etc/ssl/site.crt; 
 ssl_certificate_key /etc/ssl/site.key; # the port nginx is listening on
 server_name site.ru www.site.ru; # setup your domain here
 root /root/site;

 gzip on;
 gzip_types text/plain application/xml text/css application/javascript;
 gzip_min_length 1000;

 location / {
 expires $expires;

 "proxy_redirect" off;
 proxy_set_header Host $Host;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_set_header X-Forwarded-Proto $scheme;
 proxy_read_timeout 1m;
 proxy_connect_timeout 1m;
 proxy_pass http://127.0.0.1:3001; # set the adress of the Node.js instance here
}

 location /api/ {
 "proxy_redirect" off;
 proxy_set_header Host $Host;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_set_header X-Forwarded-Proto $scheme;
 proxy_read_timeout 1m;
 proxy_connect_timeout 1m;
 proxy_pass https://127.0.0.1:3000;
}
}



And if you go to the website to site.ru/api the express sees it as the address on the address /api/ and I need that it the address was mistaken for the root of the / ie is cannot get /api/ return the transfer from the server
app.get('/', function(req, res){

}

I think it is because the express api started in the directory root/api/server.js and the website in the root/site
March 23rd 20 at 18:45
1 answer
March 23rd 20 at 18:47
Solution
With nginx to indicate the end of the url, proxy_pass slash:
proxy_pass http://127.0.0.1:3000/;
Characterized in that if in the "proxy_pass" to specify in the uri path (in this case the path is /), then nginx will perform the conversion means and /api/ reflect on /, and not pass the request uri as it is.

Find more questions by tags Express.jsNode.jsNginx