我正在尝试在单独的文件夹上为多个版本的项目设置ningx服务器文件。我读了很多不同的概念和解决方案,但没有得到任何地方,我不知道什么是正确的,所以..用于多个Yii2高级项目位置的Nginx配置(部署开发)
目的,是建立一个良好的架构,同时开发一个API具有不同的功能,但不想合并到我们的Dev分支的是,这样的:
- api.example.com/v1/user/auth(开发)
- api.example.com/ 功能/我 - 新分支/v1/user/auth(my-new-branch)
1.结构
/var/www/html/project-api/
/dev/
api/ <- Advanced Yii2 Environment as frontend/backend
modules/
v1/
controllers/
models/
web/
index.php
common/
vendor/
...
/my-new-branch/
api/
modules/
v1/
controllers/
models/
web/
index.php
common/
vendor/
...
/*/ <- Deploying more equal branches for in progress features
2. Nginx的
server {
listen 80;
root /var/www/html/project-api/src/api/web;
index index.php index.html index.htm;
server_name api.example.com;
error_log /var/log/nginx/project-api/dev-error.log notice;
access_log off;
location/{
try_files $uri $uri/ /index.php$is_args$args;
}
## Features (not working)
location ~* ^/features/my-new-branch/(.+)$ {
root /var/www/html/project-api/my-new-branch/api/web;
try_files /api/web/$1 /api/web/$1/ /features/my-new-branch/index.php?$args;
index /features/my-new-branch/$1/index.php;
location ~ /\.(ht|git) {
deny all;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_param SCRIPT_FILENAME $document_root/api/web/$1;
fastcgi_pass unix:/var/run/php/php-fpm.sock;
include fastcgi_params;
}
}
###########
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# pass the PHP scripts to FastCGI server listening on socket
#
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
}
location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
access_log off;
log_not_found off;
expires 30d;
}
# deny access to . files, for security
#
location ~ /\. {
log_not_found off;
deny all;
}
}
我有我的服务的开发分支为正常的PHP网站当前的服务器配置,但我没有找到一个很好的解决方案为多个PHP项目nginx,在不同的根和公共文件夹(网络)上的这种结构。
任何解决方案? 别名,根,重写,sublocations ..?
(稍后)将我们的“我的新分支”作为变量以使其动态变化,因为我在项目文件夹上部署了新功能。
感谢