vicodin
vicodin

Reputation: 131

Nginx proxy pass to subdirectory react app production in docker container

I trying to run my builded react app as subdirectory of my domain (eg: mydomain.com/apps/one/client). It runs in docker container with nginx config I provided:

server {

  listen 80;

  location / {
    root   /usr/share/nginx/html;
    index  index.html index.htm;

    try_files $uri /index.html;
  }

  error_page   500 502 503 504  /50x.html;

  location = /50x.html {
    root   /usr/share/nginx/html;
  }

}

That app run with docker compose where I map the 80 container port to 3041 in my server machine. And then on my server machine I have nginx config like that:

server {
    listen 443 ssl;

    client_max_body_size 0;

    server_name mydomain.com;
    (cert settings)[...]

    location /apps/one/client {
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $http_host;
        proxy_pass http://localhost:3041/apps/one/client;
    }
    (other locations config)[...]
}

But I have got error in console app Uncaught SyntaxError: Unexpected token '<'. I tried a lot of different variations, but I still cannot achieve what I want - working app on subdirectory of my domain path. How should the nginx config looks in that case? I would be very grateful for help.

Upvotes: 2

Views: 2078

Answers (1)

vicodin
vicodin

Reputation: 131

I found solution. The problem was probably in lack of slash on the end of url. Finally I have:

location /apps/one/client/ {
    proxy_pass http://localhost:3041/;
}

And works as expected.

Upvotes: 3

Related Questions