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
ı think problem is Browser Router. Can u try hash router?
update the /admin/ location block