I want to run a Reactjs application with Nginx, I want to run it with location /admin
This is the router configuration in my Reactjs application
<code>const RouterConfig = () => {
return (
<Switch>
<Route path="/public" component={(props: any) => <UserLayout {...props} />} />
<ProtectedRoute path="/">
<AppLayout />
</ProtectedRoute>
<ProtectedRoute path="/admin">
<AppLayout />
</ProtectedRoute>
<ProtectedRoute path={['/dashboard', '/support', '/settings']}>
<DashBoardLayout />
</ProtectedRoute>
<Route exact path="/">
<AppLayout />
</Route>
</Switch>
);
};
</code>
<code>const RouterConfig = () => {
return (
<Switch>
<Route path="/public" component={(props: any) => <UserLayout {...props} />} />
<ProtectedRoute path="/">
<AppLayout />
</ProtectedRoute>
<ProtectedRoute path="/admin">
<AppLayout />
</ProtectedRoute>
<ProtectedRoute path={['/dashboard', '/support', '/settings']}>
<DashBoardLayout />
</ProtectedRoute>
<Route exact path="/">
<AppLayout />
</Route>
</Switch>
);
};
</code>
const RouterConfig = () => {
return (
<Switch>
<Route path="/public" component={(props: any) => <UserLayout {...props} />} />
<ProtectedRoute path="/">
<AppLayout />
</ProtectedRoute>
<ProtectedRoute path="/admin">
<AppLayout />
</ProtectedRoute>
<ProtectedRoute path={['/dashboard', '/support', '/settings']}>
<DashBoardLayout />
</ProtectedRoute>
<Route exact path="/">
<AppLayout />
</Route>
</Switch>
);
};
I run Reactjs application with pm2 on port 3000 and here is my Nginx config
<code> location ^~ /admin {
proxy_pass http://localhost:3000/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
rewrite ^/admin(/.*)$ $1 break;
}
</code>
<code> location ^~ /admin {
proxy_pass http://localhost:3000/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
rewrite ^/admin(/.*)$ $1 break;
}
</code>
location ^~ /admin {
proxy_pass http://localhost:3000/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
rewrite ^/admin(/.*)$ $1 break;
}
but when I access
server_name/admin
I get a white screen, maybe the router is wrong but I don’t know how to fix it
Can you guys tell me how to fix it?