nginx 代理ssh

events {
    worker_connections 1024;
}
stream { #stream模块,就跟http模块一样  
        upstream ssh {
                server 127.0.0.1:22;
        }
        server { #里面可以有多个监听服务,配置监听端口和代理的ip和端口就可以进行tcp代理了。  
                listen 9922;
                proxy_pass ssh;
                proxy_connect_timeout 1h;
                proxy_timeout 1h;
        }
}

  

 http代理

server {
    listen 8844;
    server_name 127.0.0.1;

    location / {
        proxy_read_timeout 1800;
        proxy_next_upstream http_502 http_504 error timeout invalid_header;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_pass http://192.168.1.253:808;
    }
}

  

  • 日志

stream{
log_format proxy '[$time_local] remote_addr:$remote_addr $protocol status:$status $bytes_sent $bytes_received s_time:$session_time upstream_addr:$upstream_addr u_conn_time:$upstream_connect_time';
    access_log logs/tcp-access.log proxy ;

}

参数 说明 示例
$remote_addr 客户端地址 211.28.65.253
$remote_user 客户端用户名称 --
$time_local 访问时间和时区 18/Jul/2012:17:00:01 +0800
$request 请求的URI和HTTP协议 "GET /article-10000.html HTTP/1.1"
$http_host 请求地址,即浏览器中你输入的地址(IP或域名) www.0.com
192.168.100.100
$status HTTP请求状态 200
$upstream_status upstream状态 200
$body_bytes_sent 发送给客户端文件内容大小 1547
$http_referer url跳转来源 https://www.baidu.com/
$http_user_agent 用户终端浏览器等信息 "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SV1; GTB7.0; .NET4.0C;
$ssl_protocol SSL协议版本 TLSv1
$ssl_cipher 交换数据中的算法 RC4-SHA
$upstream_addr

后台upstream的地址,即真正提供服务的主机地址;

当ngnix做负载均衡时,可以查看后台提供真实服务的设备

10.10.10.100:80
$request_time 整个请求的总时间 0.205
$upstream_response_time 请求过程中,upstream响应时间 0.002
 
 

sudo vi /etc/nginx/nginx.conf
sudo systemctl reload nginx

原文地址:https://www.cnblogs.com/ahuo/p/9362951.html