nginx –来自/ subfolder的proxy_pass –目标文件404'ing。重写规则要求?

我有两台运行nginx的服务器:

服务器1上有一系列项目 服务器2具有新的Vue / Nuxtjs(节点)

在服务器1上,我已为运行基于节点的应用程序的服务器2的静态IP设置了proxy_pass。因此,目标是让用户在浏览网站时只看到http://domain.tld/folderhttp://domain.tld/folder/login

服务器1:

location /folder/ { 
  proxy_pass http://200.1.1.1/; // IP of server 2
}

服务器2:

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

这部分起作用,但所有资产均为40​​4。点击链接时,浏览器访问http://domain.tld/login

[更新] 完整的服务器2 nginx配置(注释了一些东西以避免冲突):

server {
  listen 80;
  listen 443;


# set path to your project dir
  set $root_path /root/app;

# static content directory
  root $root_path/client/nuxt-dist/dist;

# proxy to nuxt renderer
  try_files $uri $uri/ @nodeproxy;

  location @nodeproxy {
    proxy_pass http://localhost:3000;
  }

# entry point for API server,if you have one
  location /api {
    proxy_pass http://localhost:3001;
    client_max_body_size 3m;
  }

# serve nuxt bundle with max cache life. Only compatible with nuxt 2.*
#  location ~^\/_nuxt(.*)$ {
#    alias $root_path/client/.nuxt/dist/client/$1;
#    gzip on;
#    gzip_comp_level 6;
#    gzip_vary on;
#    gzip_types text/css application/json application/javascript text/javascript application/x-font-ttf font/opentype;
#    expires max;
#  }

# serve static content
  location ~* \.(js|jpg|jpeg|txt|png|css|pdf|ico|map)$ {
    gzip_static on;
    expires 30d;
  }

# refirect from /path/ to /path
#  rewrite ^/(.*)/$ /$1 permanent;
}
mingfan007 回答:nginx –来自/ subfolder的proxy_pass –目标文件404'ing。重写规则要求?

更新:这是实现此目标的方法:

server {
  try_files $uri $uri/ @nodeproxy;

  location @nodeproxy {
    proxy_pass http://localhost:3000;
  }
}
本文链接:https://www.f2er.com/3134439.html

大家都在问