說明
因?yàn)樵诠ぷ髦邢臃停覀兊能浖窃诓粩嗌?jí),比如現(xiàn)在是v0.4版本掺炭,但是以后會(huì)升級(jí)到v0.5辫诅。這時(shí),我們要保證兩點(diǎn):
- 不帶版本訪問的時(shí)候竹伸,訪問到的是最新版本泥栖。
- 帶版本訪問的時(shí)候簇宽,訪問的是指定版本的服務(wù)。
例如:訪問v0.5的時(shí)候吧享,可以調(diào)到v0.5的程序魏割;在訪問舊的v0.4的時(shí)候,訪問的就是v0.4的版本钢颂。
這里簡(jiǎn)單說明下:
配置
這里比較懶钞它,直接copy了!
server {
listen 80;
server_name api.m.example.com;
charset utf-8;
root /home/app/api.m.example.com/v0.5/web/; #默認(rèn)路徑殊鞭,指向最新版本v0.5遭垛。不帶版本時(shí),訪問的就是最新版本v0.5操灿。
location / {
index index.php index.html index.htm; #站點(diǎn)目錄index設(shè)置
}
#當(dāng)訪問/v0.4/版本目錄時(shí)锯仪,會(huì)找/home/app/api.m.example.com/v0.4/web/
location /v0.4/ {
index index.php;
alias /home/app/api.m.example.com/v0.4/web/;
}
#當(dāng)進(jìn)入v0.4目錄后,會(huì)在/home/app/api.m.example.com/v0.4/web/目錄下找index.php程序讀取
location ~ ^/v0.4/(.*\.php)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/app/api.m.example.com/v0.4/web/$1;
include fastcgi_params;
}
location /v0.5/ {
index index.php;
alias /home/app/api.m.example.com/v0.5/web/;
}
location ~ ^/v0.5/(.*\.php)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/app/api.m.example.com/v0.5/web/$1;
include fastcgi_params;
}
#此標(biāo)簽必須配置到最后面趾盐,否則會(huì)出現(xiàn)始終訪問這個(gè)location庶喜,而不訪問其他版本目錄
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
access_log /home/logs/api.m.example.com/access.log access;
error_log /home/logs/api.m.example.com/error.log info;
}