nginx 反向代理 golang web

软件集成
1209
linux
linux 举报
2020-05-26

现有两个Golang Web服务程序: web1(8080), web2(8081), 两个域名:www.xxxxx.com, www.yyyy.com 

    在一台机器上,使xxxxx.com 解析到 8080端口,yyyy.com解析到8081端口

    使用nginx进行反向代理的方法:

    一、在nginx配置文件中,添加如下配置

         server{

listen 80;

server_name  www.xxxxx.com xxxxx.com;

location /{

try_files /_not_exists @backend;

}

location @backend{

proxy_set_header X-Forwarded-For $remote_addr;

proxy_set_header Host            $http_host;

proxy_pass  http://localhost:8080;

}

}

        域名xxxxx.com,www.xxxxx.com即可解析到服务器 8080端口

       server{

listen 80;

server_name  www.yyyy.com yyyy.com;

location /{

try_files /_not_exists @backend;

}

location @backend{

proxy_set_header X-Forwarded-For $remote_addr;

proxy_set_header Host            $http_host;

proxy_pass  http://localhost:8081;

}

}

        域名yyyy.com,www.yyyy.com即可解析到服务器 8081端口。



=============

location / {
proxy_pass http://localhost:9090;#go 服务器可以指定到其他的机器上,这里设定本机服务器

#Proxy Settings
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}


倒序看帖 只看楼主
热点关注
postfix下过滤垃圾邮件的有效方法
shell脚本每行后面多了一个^M的原因和解决办法
定时检测服务,检测down掉后重启。系统检测到DMSERVER运行正常
挂载磁盘的时候遇到一个问题,挂载完磁盘之后重启服务器挂载的盘丢失了.
中标麒麟系统Your trial is EXPIRED and no VALID licens
termux 开启ssh并用用户名和密码登陆
组成共享库的目标文件和一般的目标文件有所不同,在编译时要加-fPIC和-share选项,例如:
gcc指定链接库路径后还是找不到库文件
./configure -build,-host,-target设置
关于Linux系统中configure中build,target,host中的若干问题
不用单独编译gmp、mpfr和mpc三个包,放在gcc源码下面一起编译
安装最新版本的GCC编译器(./configure执行编译报错 C++ compiler too old)
在后台用进程名运行bash脚本
shell参数判断
postfix过滤规则的几个关键规则