nginx - TuPengXiong/TuPengXiong.github.io GitHub Wiki

负载均衡

server {
                listen 80;
                server_name localhost;
                location  5672 {
                     proxy_pass http://balance;
                }
        }
 
upstream balance{
       server 192.168.0.13:5672 weight=5;
}

正向代理

server {
    listen 192.168.0.10:80;

    #access_log      logs/proxy.access.log   main;
    #error_log       logs/proxy.error.log    notice;
    access_log      off;
    error_log       off;

    location / {
        resolver   180.76.76.76;

        set $flag 0;
        if ($http_host = fonts.googleapis.com) {
            set $flag 1;
        }
        if ($http_host = ajax.googleapis.com) {
            set $flag 2;
        }

        if ($flag = 0) {
            proxy_pass http://$http_host$uri$is_args$args;
        }
        if ($flag = 1) {
            proxy_pass http://fonts.useso.com$uri$is_args$args;
        }
        if ($flag = 2) {
            proxy_pass http://ajax.useso.com$uri$is_args$args;
        }
    }
}

server {
    listen 192.168.0.10:443;

    ssl                     on;
    ssl_certificate         conf.d/jujncn.com.pem.cer;
    ssl_certificate_key     conf.d/jujncn.com.pem.clear.key;

    #access_log      logs/proxy.access.log   main;
    #error_log       logs/proxy.error.log    notice;
    access_log      off;
    error_log       off;

    #return 301 http://$http_host$request_uri;

    location / {
        resolver   180.76.76.76;

        set $flag 0;
        if ($http_host = fonts.googleapis.com) {
            set $flag 1;
        }
        if ($http_host = ajax.googleapis.com) {
            set $flag 2;
        }

        if ($flag = 0) {
            proxy_pass http://$http_host$uri$is_args$args;
        }
        if ($flag = 1) {
            proxy_pass http://fonts.useso.com$uri$is_args$args;
        }
        if ($flag = 2) {
            proxy_pass http://ajax.useso.com$uri$is_args$args;
        }
    }
}

https反向代理

server {
    location / {
         proxy_pass              http://tomcat_server;
         proxy_set_header        Host            $host;   # ???  $http_host;
         proxy_set_header        X-Real-IP       $remote_addr;
         proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
         proxy_set_header        X-Forwarded-Proto $scheme;
         add_header              Front-End-Https   on;
         proxy_redirect          off;
    }
}