zoukankan      html  css  js  c++  java
  • nginx go gin按域名分组

    server {
        charset utf-8;
        client_max_body_size 128M;
    
        listen 80; ## listen for ipv4
        #listen [::]:80 default_server ipv6only=on; ## listen for ipv6
        index test.htm;
        root /tmp;
    
        server_name t.cn;
        rewrite ^(.*) /$host$uri last;
    
        location / {
            proxy_pass http://goserver;
        }
    
    }
    upstream goserver {
        server 127.0.0.1:9205;
    }
    
    
    package main
    
    import (
        "fmt"
        "github.com/gin-gonic/gin"
        "net/http"
        _ "net/http"
    )
    
    func main () {
        defer func(){ // 必须要先声明defer,否则不能捕获到panic异常
            if err:=recover();err!=nil{
                fmt.Println(err)
            }
        }()
    
        // 初始化引擎
        engine := gin.Default()
        // 注册一个路由和处理函数
        engine.Any("/", WebRoot)
    
        tt := engine.Group("/t.cn")
        {
            tt.GET("/one", func(context *gin.Context) {
                context.String(http.StatusOK, "haha")
            })
        }
        
        // 绑定端口,然后启动应用
        engine.Run(":9205")
    }
    
    func WebRoot(context *gin.Context) {
        context.String(http.StatusOK, "hello, world")
    }
  • 相关阅读:
    2020.9.21
    企业应用架构模式003——对象-关系结构模式
    企业应用架构模式002
    企业应用架构模式001
    代码大全003/
    代码大全002/
    每日总结
    数论必刷题
    Tarjan求割点(割顶) 割边(桥)
    Luogu 2018 秋令营 Test 2
  • 原文地址:https://www.cnblogs.com/a-flydog/p/11394207.html
Copyright © 2011-2022 走看看