Nginx proxy pass causes Uncaught SyntaxError: Unexpected token '<' ReactJS application

Viewed 364

I have 2 web apps running independently at 2 different locations (locA, locB). My nginx config is as below.

    server {
    if ($host = sub.mydomain.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = sub.mydomain.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen   80;
    listen   [::]:80;
    access_log off;
    server_name sub.mydomain.com;

    client_max_body_size 20M;

   return 301 https://$server_name$request_uri;


}
server {
  listen 443 ssl;
  server_name sub.mydomain.com

  client_max_body_size 20M;

  ssl                 off;
  ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers         HIGH:!aNULL:!MD5;

  
  location / {
      return 301 /locB;
  }

  location /locA {
      proxy_pass http://192.168.1.100:1300;

      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
      proxy_http_version 1.1;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header Host $host;

      proxy_connect_timeout       6000;
      proxy_send_timeout          6000;
      proxy_read_timeout          6000;
      send_timeout                6000;

      client_max_body_size 20M;
  }

  location /locB {
      proxy_pass http://192.168.1.100:1400;

      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
      proxy_http_version 1.1;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header Host $host;

      proxy_connect_timeout       6000;
      proxy_send_timeout          6000;
      proxy_read_timeout          6000;
      send_timeout                6000;

      client_max_body_size 20M;
  }
  
  ssl_certificate /etc/letsencrypt/live/mydomain.com-0001/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/mydomain.com-0001/privkey.pem;

  #  ssl_certificate /etc/letsencrypt/live/sub.mydomain.com/fullchain.pem; # managed by Certbot
  #  ssl_certificate_key /etc/letsencrypt/live/sub.mydomain.com/privkey.pem; # managed by Certbot
}

Problem is happening to webapp at locA. On local LAN (http://192.168.1.100:1300/one-page) it works fine, but it triggers some weird error when I access https://sub.mydomain.com/locA/one-page and the page doesn't even load.

The error is:

Uncaught SyntaxError: Unexpected token '<'
main.e35d437c.chunk.js:1 
        
       Uncaught SyntaxError: Unexpected token '<'
manifest.json:1 
        
       Manifest: Line: 1, column: 1, Syntax error.

As for webapp on locB, works like a champ.

I've searched around and found a suggestion

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

But that is for the root location which I already forwarded to locB and doesn't cause any problem.

What should I change? Thanks

0 Answers
Related