您的位置:首页 > 运维架构 > Nginx

nginx socket转发设置

2017-10-13 22:10 453 查看
1.添加依赖模块,如下

--with-stream --with-stream_ssl_module


2.nginx.conf 配置,参考说明:ngx_stream_core_module

user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
.................
}

# tcp层转发的配置文件夹

include /etc/nginx/tcp.d/*.conf;


请注意,stream配置不能放到http内,即不能放到/etc/nginx/conf.d/,因为stream是通过tcp层转发,而不是http转发。

如配置在http内,启动nginx会报如下错误:

nginx: [emerg] "server" directive is not allowed here


3.在tcp.d下新建个bss_num_30001.conf文件,内容如下:

stream {
  #添加socket转发的代理
upstream proxy_forward {
hash $remote_addr consistent;
server 139.196.172.xx:80;
#server 139.224.18.xx:80;
#ip_hash;
}
  #提供转发服务,即访问forward.xxx.cn:80,并配置好请求头,会调整至proxy_forward指定的地址
server {
#listen       127.0.0.1:80;
listen       forward.xxx.cn:80;
proxy_pass xdaili_forward;

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: