react-redux-starter-kit icon indicating copy to clipboard operation
react-redux-starter-kit copied to clipboard

Deployment in production with nginx in subfolder

Open alexgrais opened this issue 10 years ago • 2 comments

I managed to deploy the app in production on the'/'path. Each time i go to example.com my app is served without issues.

Now, i just want to deploy the exact same app under /v2/-> Each time i go to example.com/v2/ the app should be served.

Except I got the following error: Uncaught SyntaxError: Unexpected token <

I followed the steps below: Edit config/environment.js -> compiler_public_path: '/v2/' Compile with BASENAME -> BASENAME='/v2/' npm run deploy:prod

Here is my nginx.conf: location /v2 { root /home/user/myapp/dist/; try_files $uri $uri/ /index.html;
}

Did i miss something ?

alexgrais avatar Jul 08 '16 17:07 alexgrais

@AlexGrs how did you manage to serve the app under / ? does it also work when refreshing on other than root routes? as I tried to add

location / { root /usr/share/nginx/html/; try_files $uri $uri/ /index.html; }

without any success still get 404 on refresh on all other routes than /

bytewiz avatar Jul 11 '16 08:07 bytewiz

Could it be your nginx is /v2, while your config is /v2/. You can use an nginx rewrite rule to see if that is the cause. Notice the trailing slash, in the config, because the router may not be triggering. Did you try redirecting /v2 to /v2/?

In betterScripts in package.json, I set basename differently, but it looks equivalent to your passing in node environment from command line. Since I only need one basename, I put it in config. "deploy:prod" { "command": "....", "env" : { "NODE_ENV": "production", "BASENAME": "/v2/", "DEBUG": "app:*" } }

brianzinn avatar Jul 29 '16 19:07 brianzinn