Debugging NGINX site config file

Viewed 331

I'm having trouble setting up Nginx site configuration file. So basically I'm serving 3 sites:

  1. Dashboard /dashboard (react-based, operates at xxx/xxx/build/index.html)
  2. API /api (node-based, operates using a proxy-pass and it works perfectly
  3. Homepage / (static, operates at xxx/yyy/zzz/index.html)

My Nginx file looks as follows:

server {
  listen 80;
  server_name mydomain.com;
  server_name xxx.xxx.xxx.xxx;
  access_log /var/log/nginx/xxxxx;
  error_log /var/log/nginx/xxxxx;

  location /dashboard/ {
    root        /var/www/xxxxx/build;
    index        index.html;
    try_files   $uri $uri/ /index.html;
  }
  location /api/ {
    proxy_pass http://localhost:5050/;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
  }
  location / {
    root        /var/www/xxxxxx;
    index       index.html;
    try_files   $uri /$uri /index.html;
  }
}

The problem lays mainly in the /dashboard path. For some reason it redirects to the homepage and never returns the actual dashboard. I'm quite inexperienced in Nginx, so I'm not quite sure how to even debug it.

1 Answers

Just a guess.

root will add your location /dashbaord behind /var/www/xxxxx/build like so:

/var/www/xxxxx/build/dashboard

That location does not exists so it tries /index.php at the end of try_files which is an "absolute path" to your homepage?

I would try using alias instead of root (which will not add /dashboard to your root path) and/or try to fix your last parameter in try_files like so:

try_files   $uri $uri/ ./index.html;
Related