skip to Main Content

I am serving a react application in an address example.com/admin

While I can serve static files, I am unable to access routes like example.com/admin/login or example.com/admin/dashboard. When I do it, I get a 404 error, though I am able to access /admin, /admin/ and static files.

This is my nginx configuration:

gzip            on;
gzip_vary       on;
gzip_proxied    any;
gzip_comp_level 6;
gzip_types      text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;

server {
  listen 5000;
  
  # gzip
  gzip            on;
  gzip_vary       on;
  gzip_proxied    any;
  gzip_comp_level 6;
  gzip_types      text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;
  
  # Application B under /admin
  location /admin/ {
    alias /usr/share/nginx/html/;
    index index.html index.htm;
    try_files $uri $uri/ /admin/index.html =404;
  }

  # Static files for Application B under /admin
  location /admin/static/ {
    alias /usr/share/nginx/html/static/;
  }

  location /admin/js/ {
    alias /usr/share/nginx/html/js/;
  }

  location /admin/css/ {
    alias /usr/share/nginx/html/css/;
  }

  location /admin/img/ {
    alias /usr/share/nginx/html/img/;
  }

  location /admin/fonts/ {
    alias /usr/share/nginx/html/fonts/;
  }

  # Catch-all route for client-side routing
  location /admin {
    try_files $uri /admin/index.html;
  }

  include /etc/nginx/extra-conf.d/*.conf;
}

2

Answers


  1. ı think problem is Browser Router. Can u try hash router?

    Login or Signup to reply.
  2. update the /admin/ location block

        index index.html;
        try_files $uri $uri/ /admin/index.html;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search