nginx的upstream模块http代理示例。

示例1:

        upstream wssh {
                hash $remote_addr consistent;
                server 172.16.0.143:5000;
        }
    server {
                listen 5888;
                server_name localhost;
        location / {
            proxy_pass http://wssh;
            proxy_set_header Host $host:$server_port;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;

            proxy_read_timeout 60s;
            proxy_set_header Connection "Upgrade";
                }
        }

示例2:

    upstream web-app {
        server 127.0.0.1:8088;
    } 
    upstream web-old {
        server 127.0.0.1:8080;
    }
  upstream web-websocket {
        server 127.0.0.1:8088;
    }
    
    
    server {
        listen       443 ssl;
        server_name  localhost;
        
        ssl                     on;  
        #指定PEM格式的证书文件   
        ssl_certificate         /nginx/ssl/server.crt;   
        #指定PEM格式的私钥文件  
        ssl_certificate_key     /nginx/ssl/server.key;  
        
        location ~ /web-app/assets/{
            root /xxx/;
            expires      24h;
        }
       location /ipran-app/websocket/ {
          proxy_pass http://web-websocket;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";
          proxy_redirect off;
          proxy_set_header Host $host:443;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          client_max_body_size 500m;
          client_body_buffer_size 128k;
          proxy_connect_timeout 300;
          proxy_send_timeout 300;
          proxy_read_timeout 150;
          proxy_buffer_size 4k;
          proxy_buffers 4 32k;
          proxy_busy_buffers_size 64k;
          proxy_temp_file_write_size 64k;
        }
        location /cgi-bin/ {
            include fastcgi_params;
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_param SCRIPT_FILENAME /apache/xxx/cgi-bin/$fastcgi_script_name;
            fastcgi_index index.pl;
        }
        location /xx3-app/ {
            proxy_pass http://web-app; 
            proxy_redirect http:// https://;
            proxy_set_header Host $http_host; 
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-Proto https;
            client_max_body_size 500m; 
            client_body_buffer_size 128k; 
            proxy_connect_timeout 600; 
            proxy_send_timeout 600; 
            proxy_read_timeout 600; 
            proxy_buffer_size 4k; 
            proxy_buffers 4 32k; 
            proxy_busy_buffers_size 64k; 
            proxy_temp_file_write_size 64k; 
        }
        location / {
            proxy_pass http://web-old; 
            proxy_redirect http:// https://;
            proxy_set_header Host $http_host; 
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-Proto https;          
            client_max_body_size 500m; 
            client_body_buffer_size 128k; 
            proxy_connect_timeout 600; 
            proxy_send_timeout 600; 
            proxy_read_timeout 600; 
            proxy_buffer_size 4k; 
            proxy_buffers 4 32k; 
            proxy_busy_buffers_size 64k; 
            proxy_temp_file_write_size 64k;
            allow all;
            deny 199.24.0.0 ;
        }
        location /xx2/ins/ {
            proxy_pass http://127.0.0.1:8901; 
            proxy_redirect off; 
            proxy_set_header Host $http_host; 
            proxy_set_header X-Real-IP $remote_addr; 
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
            client_max_body_size 100m; 
            client_body_buffer_size 128k; 
            proxy_connect_timeout 900; 
            proxy_send_timeout 900; 
            proxy_read_timeout 900; 
            proxy_buffer_size 4k; 
            proxy_buffers 4 32k; 
            proxy_busy_buffers_size 64k; 
            proxy_temp_file_write_size 64k; 
            rewrite ^/api/(.*)$ /$1 break;
        }
     location /xx1/ {
            proxy_pass http://127.0.0.1:8848;
            proxy_redirect off; 
            proxy_set_header Host $http_host; 
            proxy_set_header X-Real-IP $remote_addr; 
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
            client_max_body_size 100m; 
            client_body_buffer_size 128k; 
            proxy_connect_timeout 900; 
            proxy_send_timeout 900; 
            proxy_read_timeout 900; 
            proxy_buffer_size 4k; 
            proxy_buffers 4 32k; 
            proxy_busy_buffers_size 64k; 
            proxy_temp_file_write_size 64k; 
        }


发表评论

必填

选填

选填

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。