1、nginx 从1.9.0版本开始支持四层代理,但做四层代理时 编译需要添加 --with-stream模块
# ./configure --prefix=/usr/local/nginx--user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-file-aio --with-stream
2、nginx配置文件
user www;
worker_processes 2;
events {
worker_connections 1024;
}
stream { #stram模块 和http模块是一同等级;做四层代理时需要添加上这个模块;
server {
listen 30028; #30028端口将以4层TCP协议方式转发至后端app_sever;
proxy_pass app_server;
}
upstream app_server{
server 172.22.0.44:30028;
server 172.22.0.45:30028;
}
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}