如何在nginx上的同一域名及端口上配置两个打包后的react应用?

server {
    listen       80;
    server_name  localhost;

    location /a {
        root   /test/nginx/a;
        index  index.html index.htm;
    try_files $uri /index.html =404;
    }

    location /b {
        root   /test/nginx/b;
        index  index.html index.htm;
    try_files $uri /index.html =404;
    }
}

目前的思路我这样写是没有用的!
请问还有什么写法吗?

阅读 3.1k
2 个回答
server {
    listen       80;
    server_name  localhost;
    
    root   /test/nginx;

    location /a {
    index  /a/index.html index.htm;
    try_files $uri /index.html =404;
    }

    location /b {
    index  /b/index.html index.htm;
    try_files $uri /index.html =404;
    }
}

这样呢?

server {
    listen       80;
    server_name  localhost;

    location /a {
        alias /test/nginx/a;
        index  index.html index.htm;
        try_files $uri /a/index.html;
    }

    location /b {
        alias /test/nginx/b;
        index  index.html index.htm;
        try_files $uri /b/index.html;
    }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题