Simon Sturgess Simon Sturgess - 2 months ago 33
React JSX Question

Nginx rewrites for React app with 2 HTML pages

so I'm building a react site using browserHistory, my current Nginx setup serves index.html for all URLs, however I have split out my admin part of the site so I need any url under /admin to server admin.html but I can;t figure it out (not a server guy!).

This is my current config, any help would be greatly appreciated!

server {
listen 80;
root /www/rawnet-one-web/dist;
index index.html index.htm;
rewrite ^/(.*)/$ $1 permanent;
location / {
auth_basic "Restricted";
auth_basic_user_file /www/.htpasswd;
try_files $uri /index.html;


Based on the examples in the location documentation, you should just have to define the /admin/ location and serve the /admin.html file for any location that matches it.

location /admin/ {
  try_files $uri $uri/ /admin.html

If you want /admin to not have a trailing slash, you will need to hard code that location.

location = /admin {
  try_files /admin.html