Grayscale publishing, in short, is based on a variety of conditions, let some users use the old version, another part of the user to use the new version.
Nginx syntax itself can be regarded as a small programming language, through simple programming, can be easily implemented based on the gray-scale distribution of IP.
Requirements: Build a quasi-production environment for developers/operators to make final adjustments online. If OK, push directly to the production environment with Rsync.
Condition: office network exits have fixed IP
Workaround:
The Nginx load balancer determines the client IP address,
If the office IP, the reverse proxy to the quasi-production environment;
If not, the reverse proxy is to the production environment.
| 12345678910111213141516171819 |
upstream prod { server 192.168.1.10; server 192.168.1.11;}upstream pre-prod { server 192.168.1.100;}server { listen 80; access_log /var/log/nginx/access.log main; set$web_backend prod; if($remote_addr ~ "123.123.123.123") { set$web_backend pre-prod; } location / { proxy_pass http://$web_backend; include proxy.conf; }} |
Similarly, can also be based on different IP, set up a different site root directory, to achieve the same purpose.
| 1234567891011 |
server { listen 80; access_log /var/log/nginx/access.log main; set$rootdir "/var/www/html"; if($remote_addr ~ "123.123.123.123") { set $rootdir "/var/www/test"; } location / { root $rootdir; }} |
Similarly, you can use GeoIP to do geo-location-based grayscale publishing, not detailed.
Note: The SET command relies on the rewrite module.
SOURCE http://purplegrape.blog.51cto.com/1330104/1403123
Nginx Grayscale Publishing based on IP