Nginx Publishing in grayscale based on IP

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.