欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

nginx stream 模块的应用 博客分类: nginx  

程序员文章站 2024-03-19 20:06:10
...

nginx 作为反向代理服务器,通常以7层网络代理为主 , 特殊情况下 也可以进行4层网络代理,实现所谓的透传,以下是一个实例



user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

stream {
    upstream localhost-443 {
    server 127.0.0.1:{{grafana_web_port}};
    }
    server {
        listen 443  ;
        proxy_pass localhost-443;
    }
}

http {
    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  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

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

    include /etc/nginx/conf.d/*.conf;
    
    upstream platform-t{
         server 127.0.0.1:8443;
    }
    server {
        listen       444 ;
        server_name  _;
        root         /usr/share/nginx/html;
        index index.html index.htm;
        ssl on;
        ssl_certificate  /opt/cert/server.crt; 
        ssl_certificate_key  /opt/cert/server.key;

        # Load configuration files for the default server block.

        location /profile {
           proxy_pass https://platform-t;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }


}