Multiple Vue apps in docker nginx - can't rewrite location root path

Viewed 412

I try to serve two Vue applications in containers via docker nginx. The problem is - if I set root for each location like this, I get 404 on GET urls.

server {
    listen          80;
    server_name     localhost;

    location /backend/api {
        proxy_pass http://backend-diagnostics/api;
    }

    location ^~ /constructor {
        root /client/constructor;
        index index.html;
        try_files $uri /index.html;
    }

    location ^~ /viewer {
        root /client/viewer;
        index index.html;
        try_files $uri /index.html;
    }
}
    

nginx has a log: "[error] 28#28: *3 open() "/etc/nginx/html/index.html" failed (2: No such file or directory)"

If I add root to server block, like this

server {
    listen          80;
    server_name     localhost;

    root /client/constructor;
    index index.html;

    location /backend/api {
        proxy_pass http://backend-diagnostics/api;
    }

    location ^~ /constructor {
        root /client/constructor;
        index index.html;
        try_files $uri /index.html;
    }

    location ^~ /viewer {
        root /client/viewer;
        index index.html;
        try_files $uri /index.html;
    }
}
    

constructor app starts to work, but if I get localhost/viewer, I get result like if I'm trying to get localhost/constructor.

If I set location like this

location /viewer {...}

the request returns blank page. Source includes text We're sorry but constructor-client doesn't work properly without JavaScript enabled. Please enable it to continue.

Docker compose file, if it's necessary

version: "3"

services:
  backend-diagnostics:
    build: ./backend
    command: bash -c "pm2-runtime start app.js"
    env_file: ./backend/.env.staging
    ports:
      - 8080:80
    # expose:
    #   - 80
  
  constructor-client:
    build: ./constructor-client
    command: bash -c "cp -r /app/dist/* /dist/"
    # ports:
    #   - 8081:80
    volumes:
      - ./client/constructor:/dist

  viewer:
    build: ./viewer-client
    command: bash -c "cp -r /app/dist/* /dist/"
    # ports:
    #   - 8082:8082
    volumes:
      - ./client/viewer:/dist

  
  nginx:
    build: ./nginx
    ports:
      - 80:80
      - 443:443
    links:
      - backend-diagnostics
    #   - constructor-client
    #   - viewer
    volumes:
      - ./client/constructor:/client/constructor
      - ./client/viewer:/client/viewer
0 Answers
Related