zoukankan      html  css  js  c++  java
  • nginx 多级7层代理安装配置

    编译安装

    yum install zlib-devel -y

    wget https://nginx.org/download/nginx-1.15.12.tar.gz

    tar -zxf nginx-1.15.12.tar.gz

    ./configure --with-stream --prefix=/usr/local/nginx-1.15.12

    make && make install


    cd /usr/local/ && ln -s nginx-1.15.12 nginx


    启动脚本


    cat > /etc/systemd/system/nginx.service <<EOF
    [Unit]
    Description=nginx proxy
    After=network.target
    After=network-online.target
    Wants=network-online.target

    [Service]
    Type=forking
    ExecStartPre=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf -p /usr/local/nginx -t
    ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf -p /usr/local/nginx
    ExecReload=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf -p /usr/local/nginx -s reload
    PrivateTmp=true
    Restart=always
    RestartSec=5
    StartLimitInterval=0
    LimitNOFILE=65536

    [Install]
    WantedBy=multi-user.target
    EOF


    配置文件


    [root@wsjy-proxy01 conf]# cat nginx.conf
    worker_processes 1;
    
    events {
        worker_connections  1024;
    }
    
    
    http {
        include       mime.types;
        default_type  application/octet-stream;
    
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
    
        sendfile        on;
        keepalive_timeout  65;
        
        upstream wsjy-proxy {
            hash $remote_addr consistent;
            server 10.101.99.121:30080;
            server 10.101.99.122:30080;
            server 10.101.99.123:30080;
        }
    
    
        server {
            listen       80;
            location / {
              proxy_set_header X-Real-IP $remote_addr;
              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
              proxy_pass http://wsjy-proxy;
              proxy_set_header Host $http_host;
              proxy_set_header Connection close;
              proxy_redirect  off;
            }
            access_log  logs/http-proxy-80.log  main;
    
            }
       
    }


    多级代理配置

    重点需将 http_host 变量传递至后端,否则可能到第二级代理会找不到资源。

    proxy_set_header Host $http_host;

    proxy_set_header Connection close;

  • 相关阅读:
    this,static,执行程序的顺序等等留意点
    PHP 中的 $this, static , self ,parent 等等关键字的总结
    css的继承之width属性(容易忽略)
    SDK和API之间有什么关系呢?
    JDK8下载账号分享
    Google大数据三篇著名论文-中文版
    HBase性能优化方法总结
    Hbase原理解析
    Java多线程
    XMind 是一个全功能的思维导图和头脑风暴软件,为激发灵感和创意而生
  • 原文地址:https://www.cnblogs.com/bugbeta/p/10886134.html
Copyright © 2011-2022 走看看