nginx实现ssh和http代理转发

cat /app/nginx/conf/nginx.conf
user  www;
worker_processes  auto;
events {
    worker_connections  65535;
    }
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"';

    access_log  /app/nginx/logs/access.log  main;
    sendfile        on;
    keepalive_timeout  65;
}
stream {
    log_format proxy '$remote_addr [$time_local] '
                 '$protocol $status $bytes_sent $bytes_received '
                 '$session_time "$upstream_addr" '
                 '"$upstream_bytes_sent" "$upstream_bytes_received" "$upstream_connect_time"';

    include  /app/nginx/conf/entry.conf;
}

[root@idn-jumpserver conf]# cat /app/nginx/conf/entry.conf
include  /app/nginx/conf/ssh-http.conf;
[root@idn-jumpserver conf]# cat ssh-http.conf 
    server {
        listen     2222;
        proxy_pass 1.12.23.19:2222;
        proxy_connect_timeout 1h;
        proxy_timeout 1h;
        error_log  /app/nginx/logs/error.log
        }
    server {
        listen     80;
        proxy_pass 1.12.23.19:80;
        proxy_connect_timeout 1h;
        proxy_timeout 1h;
        error_log  /app/nginx/logs/error.log
    }

 

配置完成后就可以实现ssh中专到目标机器了,注意开启防火墙规则,目标机器开启跳板机允许远程的端口

posted @ 2021-11-13 12:22  缺个好听的昵称  阅读(548)  评论(0编辑  收藏  举报