我正在使用Unicorn作为我的Web应用程序前面的应用程序服务器。 我希望通过同时运行两个版本的站点来进行蓝/绿色testing。 问题是根path是从一个版本的网站到另一个不同。 有没有办法做到这一点?
这是我的configuration。 现在它不起作用,因为当第二台服务器出现循环时,文件被破坏,因为它们不在根path。
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; }
编辑:我添加了一个我认为是正确的答案。
我相当肯定我明白了。 基本上我需要移动根path到资产位置,然后添加一个额外的回退,如果资产被发现。
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; }