[英]How can I serve nested projects in Nginx
I have a Lumen api project with multiple git tags for api versioning. 我有一个带有多个git标签的Lumen api项目,用于api版本控制。 So I have to deploy multiple checkouts of the project.
所以我必须部署项目的多个签出。
The folder structure on the server looks like this: 服务器上的文件夹结构如下所示:
var
www
api-staging
master
v1
public
index.php
...
v2
public
index.php
...
lastest
public
index.php
...
...
Now I'd like to serve the projects via nginx so that the url looks something like this. 现在我想通过nginx服务这些项目,以便url看起来像这样。
http://BRANCH.domain.tld/VERSION/ eg. http://BRANCH.domain.tld/VERSION/例如。 http://master.domain.tld/lastest/
HTTP://master.domain.tld/lastest/
I have tried a lot with regexp, but nothing really worked. 我用regexp尝试了很多,但没有真正有效。 I hope you can help me out.
我希望你能帮助我。
You will need to capture the BRANCH
using a regular expression server_name
statement. 您需要使用正则表达式
server_name
语句捕获BRANCH
。 See this document for more. 有关更多信息,请参阅此文
The root is constructed by appending /public
to the captured VERSION
, which requires a regular expression location
and an alias
statement. 通过将
/public
附加到捕获的VERSION
来构造根,这需要正则表达式location
和alias
语句。 See this document for more. 有关更多信息,请参阅此文
For example: 例如:
server {
...
server_name ~^(?<branch>.+)\.domain\.tld$;
location ~ ^/(?<version>[^/]+)/(?<name>.*)$ {
alias /var/www/api-staging/$branch$version/public/$name;
if (!-e $request_filename) { rewrite ^ $version/index.php last; }
location ~ \.php$ {
if (!-f $request_filename) { return 404; }
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
...
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.