简体   繁体   中英

setup nginx.config to support a location using regex to alias

My nginx.conf is configured to map http://localhost/graph to the alias web-graph .

See code below:

location ^~ /graph {
  alias $workspace/web-graph;
  break;
}

I would like to use RegEx to map anything that starts with /graph to the alias web-graph , but I am not having any luck.

An example of the code I have been trying is below:

location ~ ^/(graph)/(.*)$ {
  alias $workspace/web-graph;
  break;
}

Any suggestions would be very helpful. Thanks!

It sounds like you may be covered with one of the cases mentioned in the official docs for alias .

If not, please post some specific examples of URIs that people would request and the file paths that would be returned for them.

You don't provide enough information. When you say "not having luck", what actually happened vs what you expected to happen?

You should also review your config to make sure that the request isn't handled by some other location. The Nginx config is not a simple top-down affair.

See http://nginx.org/en/docs/http/request_processing.html#simple_php_site_configuration to get an understanding of which location is actually handling your request.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM