无法使反向代理正常工作

无法使反向代理正常工作

我正在尝试使用 nginx 作为代理nodejs 应用程序。到目前为止,我所做的就是使用如下所示的命令运行 nodejsnpm --start应用程序localhost:2791bs-config.json

{
  "port": 2791,
  "server": {
      "baseDir": "src",
      "routes": {
          "/node_modules": "node_modules"
      }
   }
}

至于我的 nginx 配置,它看起来像这样:

server {
    listen 80;
    server_name demo.example.com;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    location /angular {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header HOST $http_host;
            proxy_set_header X-NginX-Proxy true;

            proxy_pass http://127.0.0.1:2791;
            proxy_redirect off;
   }
}

当我访问时,demo.example.com/angular我得到:

[1] 17.06.10 18:35:51 304 GET /index.html

到目前为止这都很好,但是同一个页面依赖于其他 js 文件,当它尝试打开它们时找不到它们,所以我收到如下错误:

[error] 18#18: *1 open() "/etc/nginx/html/node_modules/dc/dc.css" failed (2: No such file or directory), client: 81.64.208.179, server: demo.example.com, request: "GET /node_modules/dc/dc.css HTTP/1.1", host: "demo.example.com", referrer: "http://demo.example.com/angular/"
[error] 18#18: *3 open() "/etc/nginx/html/node_modules/core-js/client/shim.min.js" failed (2: No such file or directory), client: 81.64.208.179, server: demo.example.com, request: "GET /node_modules/core-js/client/shim.min.js HTTP/1.1", host: "demo.example.com", referrer: "http://demo.example.com/angular/"
[error] 21#21: *4 open() "/etc/nginx/html/browser-sync/browser-sync-client.js" failed (2: No such file or directory), client: 81.64.208.179, server: demo.example.com, request: "GET /browser-sync/browser-sync-client.js?v=2.18.8 HTTP/1.1", host: "demo.example.com", referrer: "http://demo.example.com/angular/"

我怎样才能告诉 nginx,而不是尝试在 中查找文件/etc/nginx/html来将请求传递给正在运行的节点应用程序127.0.0.1:2791我尝试添加root /home/user/quickstart_ng2d3/src配置文件,但没有成功,因为源/依赖项分散到项目的多个文件夹中,并在节点配置文件的帮助下链接在一起。谢谢你的帮助!

相关内容