通过Nginx代理转发,可实现==隐藏内网端口==进行访问,也适用于VPN场景中,具体步骤如下:
1.在Nginx配置中添加以下代码
server {
listen 80;
server_name doc.e-123.cn;
location / {
proxy_pass http://doc1.e-123.cn:7300;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
access_log /www/wwwlogs/doc_e123_access.log;
error_log /www/wwwlogs/doc_e123_error.log;
}
2.开启ssl访问
server {
listen 80;
listen 443 ssl http2;
server_name doc.e-123.cn;
#HTTP_TO_HTTPS_END
ssl_certificate /www/server/panel/ssl/doc.e-123.cn.pem;
ssl_certificate_key /www/server/panel/ssl/doc.e-123.cn.key;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
location / {
proxy_pass http://doc1.e-123.cn:7300;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
access_log /www/wwwlogs/doc_e123_access.log;
error_log /www/wwwlogs/doc_e123_error.log;
}
doc.e-123.cn.pem
和doc.e-123.cn.key
为证书文件
通过上面的设置,将使用域名doc.e-123.cn访问doc1.e-123.cn:7300的端口页面,从而实现隐藏端口的目的.