8

Nginx通过域名代理tcp端口

 1 year ago
source link: https://caihongtengxu.github.io/2020/20200314/index.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Nginx通过域名代理tcp端口

发表于 2020-03-14

  |   分类于 Linux

  |   0 Comments

碰到一种场景,使用nginx进行反向代理tcp端口,网上大部门的设置都是一个端口代理一个端口,没有一个端口通过域名代理后端多个端口的情况。


修改nginx.conf

stream {
map $ssl_preread_server_name $name {
mysql.test.com mysql;
redis.test.com redis;
default https_default_backend;
upstream mysql{
server 10.0.0.3:3306;
upstream redis{
server 10.0.0.4:6379;
upstream https_default_backend {
server 127.0.0.1:443;
server {
listen 10.0.0.1:443;
proxy_pass $name;
ssl_preread on;

stream 模块可能会没有。百度下nginx 添加stream 模块即可

stream 是一个单独的模块,不需要放在nginx-http配置中,放在nginx.conf最后即可

stream {
upstream mysql{
server 10.1.5.3:3306;
upstream redis{
server 10.1.5.4:6379;
map $server_addr $bane {
192.168.168.238 mysql;
192.168.168.239 redis;
server {
listen 80;
proxy_pass $name;

只需要把map中参数变成域名即可

转载自: https://blog.csdn.net/diyiday/article/details/107062662

-------------The End-------------

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK