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;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM