我使用 Unicorn 作为 Web 应用程序前面的应用服务器。我想通过同时运行两个版本的网站来进行蓝绿测试。问题是两个版本的网站的根路径不同。有办法吗?
这是我的配置。目前它不起作用,因为当第二台服务器以循环方式启动时,文件会损坏,因为它们不在根路径上。
upstream unicorn {
server unix:/tmp/unicorn.main.sock fail_timeout=0;
server unix:/tmp/unicorn.main_staging.sock fail_timeout=0;
}
server {
listen 80;
server_name mysite.com;
root /var/www/sites/main/current/public;
try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass https://unicorn;
}
location ~ ^/assets/ {
expires 1y;
add_header Cache-Control public;
add_header ETag "";
break;
}
error_page 500 502 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
编辑:我添加了一个我认为正确的答案。
答案1
我确信我已经搞清楚了。基本上,我需要将根路径移到资产位置,然后如果找到资产,则添加额外的回退。
upstream unicorn {
server unix:/tmp/unicorn.main.sock fail_timeout=0;
server unix:/tmp/unicorn.main_staging.sock fail_timeout=0;
}
server {
listen 80;
server_name mysite.com;
### REMOVED root /var/www/sites/main/current/public;
try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass https://unicorn;
}
location ~ ^/assets/ {
root /var/www/sites/main/current/public; ## ADDED ##
try_files $uri @altassets; ## ADDED ##
expires 1y;
add_header Cache-Control public;
add_header ETag "";
break;
}
location @altass {
root /var/www/sites/main_staging/current/public;
try_files $uri $uri/;
}
error_page 500 502 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}