nginx 反向代理 golang web

     現有兩個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端口。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章