Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect all request to same file in nginx?

Tags:

nginx

My root directory

/web/app/src

In this directory I have 2 directories /js/ and /assets/ and one file index.html

This is what I need to achieve:

Any request to /js/ or /assets/ or /index.html just serve files from root directory For example myapp.com/js/app.js servers app.js from /web/app/src/js/ directory Same with requests to /assets/

But all other requests, any other uri should result in serving index.html

For example

myapp.com/bla/bla/q?param=x Should serve index.html from web root directory

All rewrites should be internal, no http 301 redirects.

like image 906
Dmitri Avatar asked Dec 06 '22 16:12

Dmitri


1 Answers

Sir, please try below code. :)

server {
   ...
   root /web/app/src;
   ...
   location / {
      try_files $uri $uri/ /index.html;
   }
}
like image 132
Satys Avatar answered Dec 30 '22 12:12

Satys