Vue.js Nginx spa(vue)子路径路由 我想要这样的东西: example.com/anything(公共网站) example.com/app/(vue应用程序) example.com/api/(后端api)

Vue.js Nginx spa(vue)子路径路由 我想要这样的东西: example.com/anything(公共网站) example.com/app/(vue应用程序) example.com/api/(后端api),vue.js,nginx,routing,Vue.js,Nginx,Routing,因此,我在Ubuntu服务器“/srv/root”上有一个带有static index.html(公共站点)的文件夹和带有vue应用程序的“app”文件夹: 1。对于后端API,我只需要重定向到本地端口: location /api/ { proxy_pass http://localhost:5000/api/; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade;

因此,我在Ubuntu服务器“/srv/root”上有一个带有static index.html(公共站点)的文件夹和带有vue应用程序的“app”文件夹:

1。对于后端API,我只需要重定向到本地端口:

location /api/ {
    proxy_pass         http://localhost:5000/api/;
    proxy_http_version 1.1;
    proxy_set_header   Upgrade $http_upgrade;
    proxy_set_header   Connection keep-alive;
    proxy_set_header   Host $host;
    proxy_cache_bypass $http_upgrade;
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header   X-Forwarded-Proto $scheme;
  }
  location / {
    root /srv/root/;
    try_files $uri $uri/ /index.html;
  }
  location /app {
    root /srv/root;
    try_files $uri $uri/ /index.html;
  }

  location /app/ {
    root /srv/root;
    try_files $uri $uri/ /index.html;
  }
 location ~* ^\/app\/(?!(index\.html|favicon\.ico|css\/|fonts\/|img\/|js\/)).+$ {
    root /srv/root;
    rewrite ^\/app\/(?!(index\.html|favicon\.ico|css\/|fonts\/|img\/|js\/)).*$ /app last;
    try_files $uri $uri/ /index.html;
  }
2。公共站点看起来很简单:

location /api/ {
    proxy_pass         http://localhost:5000/api/;
    proxy_http_version 1.1;
    proxy_set_header   Upgrade $http_upgrade;
    proxy_set_header   Connection keep-alive;
    proxy_set_header   Host $host;
    proxy_cache_bypass $http_upgrade;
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header   X-Forwarded-Proto $scheme;
  }
  location / {
    root /srv/root/;
    try_files $uri $uri/ /index.html;
  }
  location /app {
    root /srv/root;
    try_files $uri $uri/ /index.html;
  }

  location /app/ {
    root /srv/root;
    try_files $uri $uri/ /index.html;
  }
 location ~* ^\/app\/(?!(index\.html|favicon\.ico|css\/|fonts\/|img\/|js\/)).+$ {
    root /srv/root;
    rewrite ^\/app\/(?!(index\.html|favicon\.ico|css\/|fonts\/|img\/|js\/)).*$ /app last;
    try_files $uri $uri/ /index.html;
  }
3。vue虚拟路由的根目录看起来也很简单:

location /api/ {
    proxy_pass         http://localhost:5000/api/;
    proxy_http_version 1.1;
    proxy_set_header   Upgrade $http_upgrade;
    proxy_set_header   Connection keep-alive;
    proxy_set_header   Host $host;
    proxy_cache_bypass $http_upgrade;
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header   X-Forwarded-Proto $scheme;
  }
  location / {
    root /srv/root/;
    try_files $uri $uri/ /index.html;
  }
  location /app {
    root /srv/root;
    try_files $uri $uri/ /index.html;
  }

  location /app/ {
    root /srv/root;
    try_files $uri $uri/ /index.html;
  }
 location ~* ^\/app\/(?!(index\.html|favicon\.ico|css\/|fonts\/|img\/|js\/)).+$ {
    root /srv/root;
    rewrite ^\/app\/(?!(index\.html|favicon\.ico|css\/|fonts\/|img\/|js\/)).*$ /app last;
    try_files $uri $uri/ /index.html;
  }
4。然后,对于所有特定的子路由(如/app/overview/dashboard),我需要返回index.html,vue应用程序资源除外:

location /api/ {
    proxy_pass         http://localhost:5000/api/;
    proxy_http_version 1.1;
    proxy_set_header   Upgrade $http_upgrade;
    proxy_set_header   Connection keep-alive;
    proxy_set_header   Host $host;
    proxy_cache_bypass $http_upgrade;
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header   X-Forwarded-Proto $scheme;
  }
  location / {
    root /srv/root/;
    try_files $uri $uri/ /index.html;
  }
  location /app {
    root /srv/root;
    try_files $uri $uri/ /index.html;
  }

  location /app/ {
    root /srv/root;
    try_files $uri $uri/ /index.html;
  }
 location ~* ^\/app\/(?!(index\.html|favicon\.ico|css\/|fonts\/|img\/|js\/)).+$ {
    root /srv/root;
    rewrite ^\/app\/(?!(index\.html|favicon\.ico|css\/|fonts\/|img\/|js\/)).*$ /app last;
    try_files $uri $uri/ /index.html;
  }
问题是当我在虚拟“example.com/app/overview/dashboard”上刷新页面时,浏览器返回根页面:“example.com/app/”。因此,vue应用程序不知道源请求的url,它总是获取根。 我怎样才能修好它


/etc/nginx/可用站点/默认

server {
  listen 80 default_server;
  listen [::]:80 default_server;
  server_name example.com *.example.com;
  return 301 https://$server_name$request_uri;
}

server {
  #rewrite_log on;
  #error_log /var/log/nginx/example.com.error_log debug;

  listen 443 ssl;
  server_name example.com *.example.com;

  ssl_certificate /etc/example.com/bundle.crt;
  ssl_certificate_key /etc/example.com/private.key;

  include /etc/nginx/proxy_params;
  index index.html;

  location / {
    root /srv/root/;
    try_files $uri $uri/ /index.html;
  }

  location /app {
    root /srv/Floom.Web;
    try_files $uri $uri/ /index.html;
  }

  location /app/ {
    root /srv/Floom.Web;
    try_files $uri $uri/ /index.html;
  }

  location ~* ^\/app\/(?!(index\.html|favicon\.ico|css\/|fonts\/|img\/|js\/)).+$ {
    root /srv/Floom.Web;
    rewrite ^\/app\/(?!(index\.html|favicon\.ico|css\/|fonts\/|img\/|js\/)).*$ /app last;
    try_files $uri $uri/ /index.html;
  }

  location /api/ {
    proxy_pass         http://localhost:5000/api/;
    proxy_http_version 1.1;
    proxy_set_header   Upgrade $http_upgrade;
    proxy_set_header   Connection keep-alive;
    proxy_set_header   Host $host;
    proxy_cache_bypass $http_upgrade;
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header   X-Forwarded-Proto $scheme;
  }
}

/var/log/nginx/floom.error\u log

2019/11/14 09:34:08 [debug] 13096#13096: epoll add event: fd:9 op:1 ev:10000001
2019/11/14 09:34:08 [debug] 13097#13097: epoll add event: fd:9 op:1 ev:10000001
2019/11/14 09:34:08 [debug] 13098#13098: epoll add event: fd:9 op:1 ev:10000001
2019/11/14 09:34:08 [debug] 13099#13099: epoll add event: fd:9 op:1 ev:10000001
2019/11/14 09:34:16 [debug] 13096#13096: accept on 0.0.0.0:443, ready: 0
2019/11/14 09:34:16 [debug] 13096#13096: posix_memalign: 000055D8FA6FCCC0:512 @16
2019/11/14 09:34:16 [debug] 13096#13096: *1 accept: 213.80.249.126:54496 fd:15
2019/11/14 09:34:16 [debug] 13096#13096: *1 event timer add: 15: 60000:266964738
2019/11/14 09:34:16 [debug] 13096#13096: *1 reusable connection: 1
2019/11/14 09:34:16 [debug] 13096#13096: *1 epoll add event: fd:15 op:1 ev:80002001
2019/11/14 09:34:16 [debug] 13096#13096: accept on 0.0.0.0:443, ready: 0
2019/11/14 09:34:16 [debug] 13096#13096: posix_memalign: 000055D8FA6E26B0:512 @16
2019/11/14 09:34:16 [debug] 13096#13096: *2 accept: 213.80.249.126:54497 fd:16
2019/11/14 09:34:16 [debug] 13096#13096: *2 event timer add: 16: 60000:266964738
2019/11/14 09:34:16 [debug] 13096#13096: *2 reusable connection: 1
2019/11/14 09:34:16 [debug] 13096#13096: *2 epoll add event: fd:16 op:1 ev:80002001
2019/11/14 09:34:16 [debug] 13096#13096: *1 http check ssl handshake
2019/11/14 09:34:16 [debug] 13096#13096: *1 http recv(): 1
2019/11/14 09:34:16 [debug] 13096#13096: *1 https ssl handshake: 0x16
2019/11/14 09:34:16 [debug] 13096#13096: *1 tcp_nodelay
2019/11/14 09:34:16 [debug] 13096#13096: *1 SSL server name: "example.com"
2019/11/14 09:34:16 [debug] 13096#13096: *1 SSL ALPN supported by client: h2
2019/11/14 09:34:16 [debug] 13096#13096: *1 SSL ALPN supported by client: http/1.1
2019/11/14 09:34:16 [debug] 13096#13096: *1 SSL ALPN selected: http/1.1
2019/11/14 09:34:16 [debug] 13096#13096: *1 SSL_do_handshake: -1
2019/11/14 09:34:16 [debug] 13096#13096: *1 SSL_get_error: 2
2019/11/14 09:34:16 [debug] 13096#13096: *1 reusable connection: 0
2019/11/14 09:34:16 [debug] 13096#13096: *2 http check ssl handshake
2019/11/14 09:34:16 [debug] 13096#13096: *2 http recv(): 1
2019/11/14 09:34:16 [debug] 13096#13096: *2 https ssl handshake: 0x16
2019/11/14 09:34:16 [debug] 13096#13096: *2 tcp_nodelay
2019/11/14 09:34:16 [debug] 13096#13096: *2 SSL server name: "example.com"
2019/11/14 09:34:16 [debug] 13096#13096: *2 SSL ALPN supported by client: h2
2019/11/14 09:34:16 [debug] 13096#13096: *2 SSL ALPN supported by client: http/1.1
2019/11/14 09:34:16 [debug] 13096#13096: *2 SSL ALPN selected: http/1.1
2019/11/14 09:34:16 [debug] 13096#13096: *2 SSL_do_handshake: -1
2019/11/14 09:34:16 [debug] 13096#13096: *2 SSL_get_error: 2
2019/11/14 09:34:16 [debug] 13096#13096: *2 reusable connection: 0
2019/11/14 09:34:16 [debug] 13096#13096: *1 SSL handshake handler: 0
2019/11/14 09:34:16 [debug] 13096#13096: *1 SSL_do_handshake: 1
2019/11/14 09:34:16 [debug] 13096#13096: *1 SSL: TLSv1.3, cipher: "TLS_AES_256_GCM_SHA384 TLSv1.3 Kx=any Au=any Enc=AESGCM(256) Mac=AEAD"
2019/11/14 09:34:16 [debug] 13096#13096: *1 reusable connection: 1
2019/11/14 09:34:16 [debug] 13096#13096: *1 http wait request handler
2019/11/14 09:34:16 [debug] 13096#13096: *1 malloc: 000055D8FA6E30C0:1024
2019/11/14 09:34:16 [debug] 13096#13096: *1 SSL_read: 567
2019/11/14 09:34:16 [debug] 13096#13096: *1 SSL_read: -1
2019/11/14 09:34:16 [debug] 13096#13096: *1 SSL_get_error: 2
2019/11/14 09:34:16 [debug] 13096#13096: *1 reusable connection: 0
2019/11/14 09:34:16 [debug] 13096#13096: *1 posix_memalign: 000055D8FA704290:4096 @16
2019/11/14 09:34:16 [debug] 13096#13096: *1 http process request line
2019/11/14 09:34:16 [debug] 13096#13096: *1 http request line: "GET /app/overview/dashboard HTTP/1.1"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http uri: "/app/overview/dashboard"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http args: ""
2019/11/14 09:34:16 [debug] 13096#13096: *1 http exten: ""
2019/11/14 09:34:16 [debug] 13096#13096: *1 posix_memalign: 000055D8FA7052A0:4096 @16
2019/11/14 09:34:16 [debug] 13096#13096: *1 http process request header line
2019/11/14 09:34:16 [debug] 13096#13096: *1 http header: "Host: example.com"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http header: "Connection: keep-alive"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http header: "Cache-Control: max-age=0"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http header: "Upgrade-Insecure-Requests: 1"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http header: "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http header: "Sec-Fetch-User: ?1"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http header: "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http header: "Sec-Fetch-Site: same-origin"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http header: "Sec-Fetch-Mode: navigate"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http header: "Accept-Encoding: gzip, deflate, br"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http header: "Accept-Language: ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7,fr;q=0.6"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http header done
2019/11/14 09:34:16 [debug] 13096#13096: *1 event timer del: 15: 266964738
2019/11/14 09:34:16 [debug] 13096#13096: *1 generic phase: 0
2019/11/14 09:34:16 [debug] 13096#13096: *1 rewrite phase: 1
2019/11/14 09:34:16 [debug] 13096#13096: *1 test location: "/"
2019/11/14 09:34:16 [debug] 13096#13096: *1 test location: "app"
2019/11/14 09:34:16 [debug] 13096#13096: *1 test location: "/"
2019/11/14 09:34:16 [debug] 13096#13096: *1 test location: ~ "^\/app\/(?!(index\.html|favicon\.ico|css\/|fonts\/|img\/|js\/)).+$"
2019/11/14 09:34:16 [debug] 13096#13096: *1 using configuration "^\/app\/(?!(index\.html|favicon\.ico|css\/|fonts\/|img\/|js\/)).+$"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http cl:-1 max:1048576
2019/11/14 09:34:16 [debug] 13096#13096: *1 rewrite phase: 3
2019/11/14 09:34:16 [debug] 13096#13096: *1 http script regex: "^\/app\/(?!(index\.html|favicon\.ico|css\/|fonts\/|img\/|js\/)).*$"
2019/11/14 09:34:16 [notice] 13096#13096: *1 "^\/app\/(?!(index\.html|favicon\.ico|css\/|fonts\/|img\/|js\/)).*$" matches "/app/overview/dashboard", client: 213.80.249.126, server: example.com, request: "GET /app/overview/dashboard HTTP/1.1", host: "example.com"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http script copy: "/app"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http script regex end
2019/11/14 09:34:16 [notice] 13096#13096: *1 rewritten data: "/app", args: "", client: 213.80.249.126, server: example.com, request: "GET /app/overview/dashboard HTTP/1.1", host: "example.com"
2019/11/14 09:34:16 [debug] 13096#13096: *1 post rewrite phase: 4
2019/11/14 09:34:16 [debug] 13096#13096: *1 uri changes: 11
2019/11/14 09:34:16 [debug] 13096#13096: *1 test location: "/"
2019/11/14 09:34:16 [debug] 13096#13096: *1 test location: "app"
2019/11/14 09:34:16 [debug] 13096#13096: *1 test location: ~ "^\/app\/(?!(index\.html|favicon\.ico|css\/|fonts\/|img\/|js\/)).+$"
2019/11/14 09:34:16 [debug] 13096#13096: *1 using configuration "/app"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http cl:-1 max:1048576
2019/11/14 09:34:16 [debug] 13096#13096: *1 rewrite phase: 3
2019/11/14 09:34:16 [debug] 13096#13096: *1 post rewrite phase: 4
2019/11/14 09:34:16 [debug] 13096#13096: *1 generic phase: 5
2019/11/14 09:34:16 [debug] 13096#13096: *1 generic phase: 6
2019/11/14 09:34:16 [debug] 13096#13096: *1 generic phase: 7
2019/11/14 09:34:16 [debug] 13096#13096: *1 access phase: 8
2019/11/14 09:34:16 [debug] 13096#13096: *1 access phase: 9
2019/11/14 09:34:16 [debug] 13096#13096: *1 access phase: 10
2019/11/14 09:34:16 [debug] 13096#13096: *1 post access phase: 11
2019/11/14 09:34:16 [debug] 13096#13096: *1 generic phase: 12
2019/11/14 09:34:16 [debug] 13096#13096: *1 try files handler
2019/11/14 09:34:16 [debug] 13096#13096: *1 http script var: "/app"
2019/11/14 09:34:16 [debug] 13096#13096: *1 trying to use file: "/app" "/srv/root/app"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http script var: "/app"
2019/11/14 09:34:16 [debug] 13096#13096: *1 trying to use dir: "/app" "/srv/root/app"
2019/11/14 09:34:16 [debug] 13096#13096: *1 try file uri: "/app"
2019/11/14 09:34:16 [debug] 13096#13096: *1 generic phase: 13
2019/11/14 09:34:16 [debug] 13096#13096: *1 content phase: 14
2019/11/14 09:34:16 [debug] 13096#13096: *1 content phase: 15
2019/11/14 09:34:16 [debug] 13096#13096: *1 content phase: 16
2019/11/14 09:34:16 [debug] 13096#13096: *1 content phase: 17
2019/11/14 09:34:16 [debug] 13096#13096: *1 content phase: 18
2019/11/14 09:34:16 [debug] 13096#13096: *1 http filename: "/srv/root/app"
2019/11/14 09:34:16 [debug] 13096#13096: *1 add cleanup: 000055D8FA705230
2019/11/14 09:34:16 [debug] 13096#13096: *1 http static fd: -1
2019/11/14 09:34:16 [debug] 13096#13096: *1 http dir
2019/11/14 09:34:16 [debug] 13096#13096: *1 http finalize request: 301, "/app?" a:1, c:1
2019/11/14 09:34:16 [debug] 13096#13096: *1 http special response: 301, "/app?"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http set discard body
2019/11/14 09:34:16 [debug] 13096#13096: *1 xslt filter header
2019/11/14 09:34:16 [debug] 13096#13096: *1 HTTP/1.1 301 Moved Permanently
Server: nginx/1.15.9 (Ubuntu)
Date: Thu, 14 Nov 2019 09:34:16 GMT
Content-Type: text/html
Content-Length: 178
Location: https://example.com/app/
Connection: keep-alive

2019/11/14 09:34:16 [debug] 13096#13096: *1 write new buf t:1 f:0 000055D8FA7056D0, pos 000055D8FA7056D0, size: 206 file: 0, size: 0
2019/11/14 09:34:16 [debug] 13096#13096: *1 http write filter: l:0 f:0 s:206
2019/11/14 09:34:16 [debug] 13096#13096: *1 http output filter "/app?"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http copy filter: "/app?"
2019/11/14 09:34:16 [debug] 13096#13096: *1 image filter
2019/11/14 09:34:16 [debug] 13096#13096: *1 xslt filter body
2019/11/14 09:34:16 [debug] 13096#13096: *1 http postpone filter "/app?" 000055D8FA705270
2019/11/14 09:34:16 [debug] 13096#13096: *1 write old buf t:1 f:0 000055D8FA7056D0, pos 000055D8FA7056D0, size: 206 file: 0, size: 0
2019/11/14 09:34:16 [debug] 13096#13096: *1 write new buf t:0 f:0 0000000000000000, pos 000055D8F9CB8AE0, size: 116 file: 0, size: 0
2019/11/14 09:34:16 [debug] 13096#13096: *1 write new buf t:0 f:0 0000000000000000, pos 000055D8F9CB8DE0, size: 62 file: 0, size: 0
2019/11/14 09:34:16 [debug] 13096#13096: *1 http write filter: l:1 f:0 s:384
2019/11/14 09:34:16 [debug] 13096#13096: *1 http write filter limit 0
2019/11/14 09:34:16 [debug] 13096#13096: *1 posix_memalign: 000055D8FA79C6A0:512 @16
2019/11/14 09:34:16 [debug] 13096#13096: *1 malloc: 000055D8FA791C80:16384
2019/11/14 09:34:16 [debug] 13096#13096: *1 SSL buf copy: 206
2019/11/14 09:34:16 [debug] 13096#13096: *1 SSL buf copy: 116
2019/11/14 09:34:16 [debug] 13096#13096: *1 SSL buf copy: 62
2019/11/14 09:34:16 [debug] 13096#13096: *1 SSL to write: 384
2019/11/14 09:34:16 [debug] 13096#13096: *1 SSL_write: 384
2019/11/14 09:34:16 [debug] 13096#13096: *1 http write filter 0000000000000000
2019/11/14 09:34:16 [debug] 13096#13096: *1 http copy filter: 0 "/app?"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http finalize request: 0, "/app?" a:1, c:1
2019/11/14 09:34:16 [debug] 13096#13096: *1 set http keepalive handler
2019/11/14 09:34:16 [debug] 13096#13096: *1 http close request
2019/11/14 09:34:16 [debug] 13096#13096: *1 http log handler
2019/11/14 09:34:16 [debug] 13096#13096: *1 free: 000055D8FA704290, unused: 0
2019/11/14 09:34:16 [debug] 13096#13096: *1 free: 000055D8FA7052A0, unused: 2222
2019/11/14 09:34:16 [debug] 13096#13096: *1 free: 000055D8FA6E30C0
2019/11/14 09:34:16 [debug] 13096#13096: *1 hc free: 0000000000000000
2019/11/14 09:34:16 [debug] 13096#13096: *1 hc busy: 0000000000000000 0
2019/11/14 09:34:16 [debug] 13096#13096: *1 free: 000055D8FA791C80
2019/11/14 09:34:16 [debug] 13096#13096: *1 reusable connection: 1
2019/11/14 09:34:16 [debug] 13096#13096: *1 event timer add: 15: 65000:266969754
2019/11/14 09:34:16 [debug] 13096#13096: *1 http keepalive handler
2019/11/14 09:34:16 [debug] 13096#13096: *1 malloc: 000055D8FA6E30C0:1024
2019/11/14 09:34:16 [debug] 13096#13096: *1 SSL_read: 632
2019/11/14 09:34:16 [debug] 13096#13096: *1 SSL_read: -1
2019/11/14 09:34:16 [debug] 13096#13096: *1 SSL_get_error: 2
2019/11/14 09:34:16 [debug] 13096#13096: *1 reusable connection: 0
2019/11/14 09:34:16 [debug] 13096#13096: *1 posix_memalign: 000055D8FA704290:4096 @16
2019/11/14 09:34:16 [debug] 13096#13096: *1 event timer del: 15: 266969754
2019/11/14 09:34:16 [debug] 13096#13096: *1 http process request line
2019/11/14 09:34:16 [debug] 13096#13096: *1 http request line: "GET /app/ HTTP/1.1"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http uri: "/app/"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http args: ""
2019/11/14 09:34:16 [debug] 13096#13096: *1 http exten: ""
2019/11/14 09:34:16 [debug] 13096#13096: *1 posix_memalign: 000055D8FA7052A0:4096 @16
2019/11/14 09:34:16 [debug] 13096#13096: *1 http process request header line
2019/11/14 09:34:16 [debug] 13096#13096: *1 http header: "Host: example.com"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http header: "Connection: keep-alive"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http header: "Cache-Control: max-age=0"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http header: "Upgrade-Insecure-Requests: 1"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http header: "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http header: "Sec-Fetch-User: ?1"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http header: "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http header: "Sec-Fetch-Site: same-origin"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http header: "Sec-Fetch-Mode: navigate"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http header: "Accept-Encoding: gzip, deflate, br"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http header: "Accept-Language: ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7,fr;q=0.6"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http header: "If-None-Match: W/"5dcbc7e8-611""
2019/11/14 09:34:16 [debug] 13096#13096: *1 http header: "If-Modified-Since: Wed, 13 Nov 2019 09:07:52 GMT"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http header done
2019/11/14 09:34:16 [debug] 13096#13096: *1 generic phase: 0
2019/11/14 09:34:16 [debug] 13096#13096: *1 rewrite phase: 1
2019/11/14 09:34:16 [debug] 13096#13096: *1 test location: "/"
2019/11/14 09:34:16 [debug] 13096#13096: *1 test location: "app"
2019/11/14 09:34:16 [debug] 13096#13096: *1 test location: "/"
2019/11/14 09:34:16 [debug] 13096#13096: *1 test location: ~ "^\/app\/(?!(index\.html|favicon\.ico|css\/|fonts\/|img\/|js\/)).+$"
2019/11/14 09:34:16 [debug] 13096#13096: *1 using configuration "/app/"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http cl:-1 max:1048576
2019/11/14 09:34:16 [debug] 13096#13096: *1 rewrite phase: 3
2019/11/14 09:34:16 [debug] 13096#13096: *1 post rewrite phase: 4
2019/11/14 09:34:16 [debug] 13096#13096: *1 generic phase: 5
2019/11/14 09:34:16 [debug] 13096#13096: *1 generic phase: 6
2019/11/14 09:34:16 [debug] 13096#13096: *1 generic phase: 7
2019/11/14 09:34:16 [debug] 13096#13096: *1 access phase: 8
2019/11/14 09:34:16 [debug] 13096#13096: *1 access phase: 9
2019/11/14 09:34:16 [debug] 13096#13096: *1 access phase: 10
2019/11/14 09:34:16 [debug] 13096#13096: *1 post access phase: 11
2019/11/14 09:34:16 [debug] 13096#13096: *1 generic phase: 12
2019/11/14 09:34:16 [debug] 13096#13096: *1 try files handler
2019/11/14 09:34:16 [debug] 13096#13096: *1 http script var: "/app/"
2019/11/14 09:34:16 [debug] 13096#13096: *1 trying to use file: "/app/" "/srv/root/app/"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http script var: "/app/"
2019/11/14 09:34:16 [debug] 13096#13096: *1 trying to use dir: "/app/" "/srv/root/app/"
2019/11/14 09:34:16 [debug] 13096#13096: *1 try file uri: "/app/"
2019/11/14 09:34:16 [debug] 13096#13096: *1 generic phase: 13
2019/11/14 09:34:16 [debug] 13096#13096: *1 content phase: 14
2019/11/14 09:34:16 [debug] 13096#13096: *1 open index "/srv/root/app/index.html"
2019/11/14 09:34:16 [debug] 13096#13096: *1 internal redirect: "/app/index.html?"
2019/11/14 09:34:16 [debug] 13096#13096: *1 rewrite phase: 1
2019/11/14 09:34:16 [debug] 13096#13096: *1 test location: "/"
2019/11/14 09:34:16 [debug] 13096#13096: *1 test location: "app"
2019/11/14 09:34:16 [debug] 13096#13096: *1 test location: "/"
2019/11/14 09:34:16 [debug] 13096#13096: *1 test location: ~ "^\/app\/(?!(index\.html|favicon\.ico|css\/|fonts\/|img\/|js\/)).+$"
2019/11/14 09:34:16 [debug] 13096#13096: *1 using configuration "/app/"
2019/11/14 09:34:16 [debug] 13096#13096: *1 http cl:-1 max:1048576
2019/11/14 09:34:16 [debug] 13096#13096: *1 rewrite phase: 3
2019/11/14 09:34:16 [debug] 13096#13096: *1 post rewrite phase: 4
2019/11/14 09:34:16 [debug] 13096#13096: *1 generic phase: 5
2019/11/14 09:34:16 [debug] 13096#13096: *1 generic phase: 6
2019/11/14 09:34:16 [debug] 13096#13096: *1 generic phase: 7
2019/11/14 09:34:16 [debug] 13096#13096: *1 access phase: 8
2019/11/14 09:34:16 [debug] 13096#13096: *1 access phase: 9
2019/11/14 09:34:16 [debug] 13096#13096: *1 access phase: 10
2019/11/14 09:34:16 [debug] 13096#13096: *1 post access phase: 11
2019/11/14 09:34:16 [debug] 13096#13096: *1 generic phase: 12
2019/11/14 09:34:16 [debug] 13096#13096: *1 try files handler
2019/11/14 09:34:16 [debug] 13096#13096: *1 http script var: "/app/index.html"
2019/11/14 09:34:16 [debug] 13096#13096: *1 trying to use file: "/app/index.html" "/srv/root/app/index.html"
2019/11/14 09:34:16 [debug] 13096#13096: *1 try file uri: "/app/index.html"
2019/11/14 09:34:16 [debug] 13096#13096: *1 generic phase: 13
2019/11/14 09:34:16 [debug] 13096#13096: *1 content phase: 14
2019/11/14 09:34:16 [debug] 13096#13096: *1 content phase: 15
2019/11/14 09:34:16 [debug] 13096#13096: *1 content phase: 16
2019/11/14 09:34:16 [debug] 13096#13096: *1 content phase: 17
2019/11/14 09:34:16 [debug] 13096#13096: *1 content phase: 18
2019/11/14 09:34:16 [debug] 13096#13096: *1 http filename: "/srv/root/app/index.html"
2019/11/14 09:34:16 [debug] 13096#13096: *1 add cleanup: 000055D8FA7051A8
2019/11/14 09:34:16 [debug] 13096#13096: *1 http static fd: 17
2019/11/14 09:34:16 [debug] 13096#13096: *1 http set discard body
2019/11/14 09:34:16 [debug] 13096#13096: *1 http ims:1573636072 lm:1573636072
2019/11/14 09:34:16 [debug] 13096#13096: *1 http im:"W/"5dcbc7e8-611"" etag:"5dcbc7e8-611"
2019/11/14 09:34:16 [debug] 13096#13096: *1 xslt filter header
2019/11/14 09:34:16 [debug] 13096#13096: *1 HTTP/1.1 304 Not Modified
Server: nginx/1.15.9 (Ubuntu)
Date: Thu, 14 Nov 2019 09:34:16 GMT
Last-Modified: Wed, 13 Nov 2019 09:07:52 GMT
Connection: keep-alive
ETag: "5dcbc7e8-611"

2019/11/14 09:34:16 [debug] 13096#13096: *1 write new buf t:1 f:0 000055D8FA7057B8, pos 000055D8FA7057B8, size: 189 file: 0, size: 0
2019/11/14 09:34:16 [debug] 13096#13096: *1 http write filter: l:1 f:0 s:189
2019/11/14 09:34:16 [debug] 13096#13096: *1 http write filter limit 0
2019/11/14 09:34:16 [debug] 13096#13096: *1 malloc: 000055D8FA791C80:16384
2019/11/14 09:34:16 [debug] 13096#13096: *1 SSL buf copy: 189
2019/11/14 09:34:16 [debug] 13096#13096: *1 SSL to write: 189
2019/11/14 09:34:16 [debug] 13096#13096: *1 SSL_write: 189
2019/11/14 09:34:16 [debug] 13096#13096: *1 http write filter 0000000000000000
2019/11/14 09:34:16 [debug] 13096#13096: *1 http finalize request: 0, "/app/index.html?" a:1, c:2
2019/11/14 09:34:16 [debug] 13096#13096: *1 http request count:2 blk:0
2019/11/14 09:34:16 [debug] 13096#13096: *1 http finalize request: -4, "/app/index.html?" a:1, c:1
2019/11/14 09:34:16 [debug] 13096#13096: *1 set http keepalive handler
2019/11/14 09:34:16 [debug] 13096#13096: *1 http close request
2019/11/14 09:34:16 [debug] 13096#13096: *1 http log handler
2019/11/14 09:34:16 [debug] 13096#13096: *1 run cleanup: 000055D8FA7051A8
2019/11/14 09:34:16 [debug] 13096#13096: *1 file cleanup: fd:17
2019/11/14 09:34:16 [debug] 13096#13096: *1 free: 000055D8FA704290, unused: 40
2019/11/14 09:34:16 [debug] 13096#13096: *1 free: 000055D8FA7052A0, unused: 2371
2019/11/14 09:34:16 [debug] 13096#13096: *1 free: 000055D8FA6E30C0
2019/11/14 09:34:16 [debug] 13096#13096: *1 hc free: 0000000000000000
2019/11/14 09:34:16 [debug] 13096#13096: *1 hc busy: 0000000000000000 0
2019/11/14 09:34:16 [debug] 13096#13096: *1 free: 000055D8FA791C80
2019/11/14 09:34:16 [debug] 13096#13096: *1 reusable connection: 1
2019/11/14 09:34:16 [debug] 13096#13096: *1 event timer add: 15: 65000:266969762
2019/11/14 09:34:17 [debug] 13096#13096: *2 SSL handshake handler: 0
2019/11/14 09:34:17 [debug] 13096#13096: *2 SSL_do_handshake: 1
2019/11/14 09:34:17 [debug] 13096#13096: *2 SSL: TLSv1.3, cipher: "TLS_AES_256_GCM_SHA384 TLSv1.3 Kx=any Au=any Enc=AESGCM(256) Mac=AEAD"
2019/11/14 09:34:17 [debug] 13096#13096: *2 reusable connection: 1
2019/11/14 09:34:17 [debug] 13096#13096: *2 http wait request handler
2019/11/14 09:34:17 [debug] 13096#13096: *2 malloc: 000055D8FA6E30C0:1024
2019/11/14 09:34:17 [debug] 13096#13096: *2 SSL_read: -1
2019/11/14 09:34:17 [debug] 13096#13096: *2 SSL_get_error: 2
2019/11/14 09:34:17 [debug] 13096#13096: *2 free: 000055D8FA6E30C0

我不确定您是否需要步骤(4),但步骤(3)应该使用:
try\u files$uri$uri//app/index.html指向正确的索引文件。它可以工作!非常感谢。但是在这种情况下,如何将另一个SPA添加到/app2/sub目录中?请将其放入自己的
location/app2/
块中。