Javascript Nginx加载多个位置的静态文件

Javascript Nginx加载多个位置的静态文件,javascript,node.js,nginx,location,static-files,Javascript,Node.js,Nginx,Location,Static Files,我在nginx.conf文件中有多个位置,如下所示 server { ... location /api/ { client_max_body_size 0; proxy_pass http://127.0.0.1:8000/api/; proxy_redirect off; proxy_read_timeout 5m; proxy_set_header Ho

我在nginx.conf文件中有多个位置,如下所示

server {
    ...

    location /api/ {
            client_max_body_size 0;
            proxy_pass http://127.0.0.1:8000/api/;
            proxy_redirect off;
            proxy_read_timeout 5m;
            proxy_set_header Host $host;
            proxy_set_header X-Real-Ip $remote_addr;
            proxy_set_header X­Forwarded­For $proxy_add_x_forwarded_for;
    }
    ...

    location /cliente/ {
            proxy_pass http://127.0.0.1:4000/;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header HOST $http_host;
            proxy_set_header X-NginX-Proxy true;
            proxy_redirect off;
    }

   location / {
            proxy_pass http://127.0.0.1:8000/;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header HOST $http_host;
            proxy_set_header X-NginX-Proxy true;
            proxy_redirect off;
    }
在大多数情况下,这些位置是为自己的静态文件和api rest提供服务的节点服务器

每个节点应用程序中的静态文件正在加载use html文件并调用如下

/my-static-path-1/
/my-static-path-2/
问题:

当服务器尝试加载路径时,这是直接从
/
加载,并且不使用自己的子路径,导致404错误

示例:

1) url
http:/myip\u sample.com/cliente
调用nodejs应用程序或提供html文件,此文件需要加载css脚本,如
/my static path/js/sample.js

2) 此文件调用的是http://myip\u sample.com/my static path/js/sample.js而不是http://myip\u sample.com/cliente/my static path/js/sample.js

我想这样做而不改变任何东西,只使用nginx conf文件


提前谢谢

对您拥有的每个资产文件夹位置使用此选项

location /my-static-path-1 {
        alias /location/to/my-static-path-1;
    }

location /my-static-path-2 {
        alias /location/to/my-static-path-2;
    }

您可以从自己的位置/my-static-path-1/{root/var/static/;}为static提供服务