Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nginx: how to create an alias url route?

Tags:

nginx

basically an server instance is running at

somesite.com/production/folder/here?param=here&count=1

I want to point someite.com/demo to /production/folder/here so when user types somesite.com/production/demo?param=here it will work without redirecting to /production/folder/here

like image 542
KJW Avatar asked Jan 28 '14 07:01

KJW


People also ask

What is alias in nginx?

alias is used to replace the location part path (LPP) in the request path, while the root is used to be prepended to the request path. They are two ways to map the request path to the final file path. alias could only be used in location block, and it will override the outside root .

What is the difference between root and alias in a Nginx configuration?

In case of root, the URL path after domain, including location, is appended to the root folder location. In case of Alias, only the URL part without the location, is appended to Alias folder.


1 Answers

server {
  server_name example.com;
  root /path/to/root;
  location / {
    # bla bla
  }
  location /demo {
    alias /path/to/root/production/folder/here;
  }
}

If you need to use try_files inside /demo you'll need to replace alias with a root and do a rewrite because of the bug explained here

like image 93
Mohammad AbuShady Avatar answered Oct 17 '22 15:10

Mohammad AbuShady