首页 > 解决方案 > 如何为同一服务器上的三个应用程序配置我的 nginx 配置文件

问题描述

你好我有三个应用程序(反应,角度和节点)我想配置我的nginx文件有这个:mysite.com for react,mysite.com/admin for angular,pmysite.com/api for node app

    #node app
    location /api/ {
            proxy_pass http://127.0.0.1:3000;
            access_log /var/log/nginx/mysite.log;
            error_log /var/log/nginx/mysite_error.log;
    }
    #angular app
    location /admin {
    root /var/www/mysite/backoffice/dist/index.html;
                    access_log /var/log/nginx/mysite_bo.log;
            error_log /var/log/nginx/mysite_bo.log;
    }
    location ~ \.(aac|m3u8|ts) {
            root /var/www/mysite/media;
    }
    location  /uploads/ {
           root  /var/www/mysite/;
   }
   #react app
    location / {
            proxy_pass http://127.0.0.1:3006;
            access_log /var/log/nginx/mysite_react.log;
            error_log /var/log/nginx/mysite_react.log;
    }}

/admin 不工作它重定向到 / 任何解决方案?

标签: node.jsreactjsangularnginx

解决方案


root块下的路径location /admin用作与该模式匹配的所有后续请求的基本路径。看起来您已经硬编码了/admin提供单个文件的路径/var/www/mysite/backoffice/dist/index.html

尝试更改它以查看是否有效:

location /admin {
    root /var/www/mysite/backoffice/dist;   # change to this
    access_log /var/log/nginx/mysite_bo.log;
    error_log /var/log/nginx/mysite_bo.log;
}

推荐阅读