通过nginx得 tcp代理,来解决线上一些服务访问不到得情况。比如阿里云得rds是内网访问得,我们通过nginx代理,让他能够给我们直接访问了。
安装nginx得时候添加stream插件
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream --with-http_gzip_static_module --with-http_sub_module
安装地址 https://blog.csdn.net/yelllowcong/article/details/76382900
配置nginx.conf
#nginx.conf
user root root;
worker_processes auto;
error_log /home/wwwlogs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 102000;
events
{
use epoll;
worker_connections 102000;
multi_accept on;
}
http
{
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 50m;
proxy_ignore_client_abort on;
fastcgi_ignore_client_abort on;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
server_tokens off;
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" '
'$request_time "$upstream_response_time" '
'"$upstream_addr" "$upstream_connect_time"';
access_log off;
server
{
listen 80 default_server;
server_name localhost;
index index.html index.htm index.php;
root /home/wwwroot/default;
include enable-php.conf;
location /nginx_status
{
stub_status on;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /\.
{
deny all;
}
access_log /home/wwwlogs/access.log access;
}
include vhost/*.conf;
}
stream {
server {
listen 6379;
proxy_pass r-2ze414d0efc16934.redis.rds.aliyuncs.com:6379;
}
}