美文网首页
nginx反向代理tcp/udp

nginx反向代理tcp/udp

作者: _fishman | 来源:发表于2019-12-05 12:37 被阅读0次
nginx反向代理tcp/udp请求实现映射远端服务器

安装nginx,添加stram模块支持
yum和rpm安装默认是带有stram模块
查看所有模块

$ nginx -V
nginx version: nginx/1.16.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
配置文件修改

安装好nginx后就是添加tcp,udp的反向代理了。 需要注意

  • 此处的代理跟平常所说的网站反向代理不一样,这是原生的tcp,udp协议。
  • stream反向代理模块与http是等级,不要把配置写入了http里面。

配置文件示例:

user nginx;
pid /run/nginx.pid;

worker_processes 8;
worker_cpu_affinity 0001 0010 0100 1000 10000 100000 1000000 10000000;
worker_rlimit_nofile 65535;


events {
        use epoll;
        worker_connections 65535;
        accept_mutex off;
        multi_accept off;

}

stream {
    upstream backend {
         server 10.0.0.100:8080;
    }
    server {
        listen 7082;
        listen 7082 udp;
        proxy_connect_timeout 5s;
        proxy_timeout 3600s;
        proxy_pass backend;
    }
}


http {

        ##
        # Basic Settings
        ##
        server_tokens off;
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        send_timeout 10s;
        types_hash_max_size 2048;
        client_header_buffer_size 4k;
        client_max_body_size 8m;
        underscores_in_headers on;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # Logging Settings
        ##
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" $http_host '
                           '$status $request_length $body_bytes_sent "$http_referer" '
                 '"$http_user_agent"  $request_time $upstream_response_time';

        set_real_ip_from 100.64.0.0/10;
        real_ip_header X-Forwarded-For;

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;
        gzip_disable "msie6";
        gzip_min_length 1024;
        gzip_vary on;
        gzip_comp_level 2;
        gzip_buffers 32 4k;
        gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;


        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}

相关文章

  • nginx负载均衡和http代理与tcp-udp代理

    nginx自1.9.0开始提供tcp/udp的反向代理功能 web负载和代理 tcp/udp端口代理

  • (转载)nginx反向代理TCP,取RTMP流

    nginx反向代理TCP,取RTMP流 一、说明nginx默认只支持HTTP反向代理,如果需要支持TCP反向代理需...

  • nginx实现tcp反向代理

    tcp反向代理默认不在nginx的模块里,想要nginx实现反向代理tcp请求,需要自己编译tcp模块到nginx...

  • nginx反向代理tcp/udp

    nginx反向代理tcp/udp请求实现映射远端服务器 安装nginx,添加stram模块支持yum和rpm安装默...

  • Nginx

    Nginx有多种多样的用途,可以作为HTTP服务器、反向代理服务器、邮件代理服务器、普通的TCP/UDP代理服务器...

  • Nginx的TCP和UDP反向代理

    Nginx的Stream模块支持TCP和UDP转发 nginx从1.9.0版本开始,新增了ngx_stream_c...

  • nginx的tcp/udp代理

    nginx的tcp/udp代理 nginx从1.9.0版本开始,新增了ngx_stream_core_module...

  • Nginx的安装与配置

    nginx的主要功能 http服务器http服务器的反向代理imap/pop3邮件服务器tcp/udp协议的伪四层...

  • nginx tcp反向代理

    nginx1.9以上的版本支持tcp反向代理,可以把一些需要共享端口的进程轻松地实现多进程。比如取rtmp流,默认...

  • Nginx反向代理TCP

    前言 由于历史原因,我司公网的80端口与443端口并不指向同一台机器,这就导致了https和http不能在同一台机...

网友评论

      本文标题:nginx反向代理tcp/udp

      本文链接:https://www.haomeiwen.com/subject/ousdgctx.html