简体   繁体   English

设置nginx.config以支持使用正则表达式作为别名的位置

[英]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 . 我的nginx.conf配置为将http://localhost/graph映射到别名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. 我想使用RegEx将以/graph开头的任何内容映射到别名web-graph ,但是我没有任何运气。

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 . 听起来您可能被官方文档中提到alias

If not, please post some specific examples of URIs that people would request and the file paths that would be returned for them. 如果没有,请张贴一些人们将要求的URI的特定示例以及将为他们返回的文件路径。

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. Nginx配置不是简单的自上而下的事情。

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. 请参阅http://nginx.org/en/docs/http/request_processing.html#simple_php_site_configuration ,以了解实际在哪个位置处理您的请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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