nginx proxy_pass直接代理方法到外网失败 内网成功
NGINX stream (4层解决方案) HTTP CONNECT隧道 (7层解决方案)链接:
https://blog.csdn.net/qq_34777982/article/details/110439315
NGINX stream (4层解决方案)链接:
https://blog.csdn.net/carefree2005/article/details/121229818
https://blog.csdn.net/qq_52862408/article/details/131057396
环境前提
1、nginx需要支持 –with-stream,–with-stream_ssl_preread_module和–with-stream_ssl_module
yum安装的nginx默认都支持
nginx -V 查看是否支持 –with-stream,–with-stream_ssl_preread_module和–with-stream_ssl_module
看到是支持的
如果不支持就在configure的时候加上–with-stream,–with-stream_ssl_preread_module和–with-stream_ssl_module选项

2、nginx.conf 配置文件内需要加载 load_module /路径/ngx_stream_module.so;模块##nginx配置文件置顶
find / -name ngx_stream_module.so
找一下如果没有模块就 下载
报错
配置检查时报错unknown directive “stream”
报错原因:未找到stream模块
find / -name ngx_stream_module.so
找不到就下载模块
加载模块:load_module /路径/ngx_stream_module.so; ##nginx配置文件置顶
nginx代理服务器配置

load_module /usr/lib64/nginx/modules/ngx_stream_module.so; #加载模块
error_log /var/log/nginx/error.log error;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
stream {
resolver 10.192.23.21;#DNS地址
server {
listen 443;
ssl_preread on;
proxy_pass www.k8888.top:443;#不能写https://www.k8888.top:443不然报错nginx: [emerg] invalid host in upstream "https://www.k8888.top:443" in /etc/nginx/nginx.conf:15
}}
客户端设置hosts且访问
Windows hosts路径C:\Windows\System32\drivers\etc
centos hosts路径/etc/hosts
nginx代理服务器地址 www.k8888.top

