nginx 反向代理 go 服务

栏目: 服务器 · Nginx · 发布时间: 6年前

内容简介:当我们启动一个go 程序的时候,通常监听的是本地端口如 IP:port 。但是实际的线上环境,解析路径是:通过 DNS 解析 ——> nginx vhost ——> IP:port 这个。单纯的使用 go 是不能处理 域名解析工作的。所以通常是NGINX 和 Go 搭配着使用。nginx 可以帮我做很多工作,例如访问日志,cc 攻击,静态服务等,nginx 已经做的很成熟了。

当我们启动一个 go 程序的时候,通常监听的是本地端口如 IP:port 。但是实际的线上环境,解析路径是:通过 DNS 解析 ——> nginx vhost ——> IP:port 这个。单纯的使用 go 是不能处理 域名解析工作的。

所以通常是NGINX 和 Go 搭配着使用。

nginx 可以帮我做很多工作,例如访问日志,cc 攻击,静态服务等,nginx 已经做的很成熟了。

Go 只要专注于业务逻辑和功能就好。

NGINX作为反向代理的配置如下:

#列出所有服务器地址,nginx 自动均衡分发请求到各个服务器。
upstream frontends {
    ip_hash;
    server 192.168.199.1:8088;
    server 192.168.199.2:8089;
}
server
    {
        listen 80;
        server_name nav.v5u.win ;

    #静态资源交由nginx管理
     location /static {
        root        /var/www/mydomain/web;
        expires     1d;
        add_header  Cache-Control public;
        access_log  off;
        }

        # 反向代理设置
        location ~ /
            {
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                proxy_redirect off;
                proxy_pass http://localhost:7070;
            }
    }

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Chinese Authoritarianism in the Information Age

Chinese Authoritarianism in the Information Age

Routledge / 2018-2-13 / GBP 115.00

This book examines information and public opinion control by the authoritarian state in response to popular access to information and upgraded political communication channels among the citizens in co......一起来看看 《Chinese Authoritarianism in the Information Age》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具