Home > Back-end >  Nginx dynamic route
Nginx dynamic route

Time:09-30

I made a sample application that produces dynamic static files. I basically do not want to enter all the routes manually into the default file of Nginx. I saw some solutions here but the answers were not understandable for me in my simple case.

So basically my structure looks like this :

the main link of the application:

https://mysite.come/myproject/products

dynamic routes are numbers that also the link has query string for example:

https://mysite.come/myproject/products/1?rand=something
https://mysite.come/myproject/products/2?rand=something
https://mysite.come/myproject/products/3?rand=something
https://mysite.come/myproject/products/4?rand=something

I could basically write :

 location /myproject/products/1/ {
      proxy_pass http://localhost:8000/1;
   }

and need to repeat this for all the products which are none sense. Is there any way to do it automatically?

...

when I use dev mode ( npm run dev) I get

CodePudding user response:

maybe using try_files? see the last part of this article

CodePudding user response:

location /myproject/products/ {
    proxy_pass http://localhost:8000;
}

server {
    listen       8000;
    server_name  localhost;
    location / {
        root   path_of_web_bundle;
        index  index.html index.htm;
        try_files $uri $uri/ /index.html;
    }
}
  • Related