Last active
November 20, 2020 03:59
-
-
Save ifels/789b7db940f5e0fa82c9 to your computer and use it in GitHub Desktop.
通过nginx反向代理go语言写的http服务器
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
通过nginx反向代理go语言写的http服务器 | |
1. nginx 配置 | |
#列出所有服务器地址,nginx 自动均衡分发请求到各个服务器。 | |
upstream frontends { | |
ip_hash; | |
server 192.168.199.1:8088; | |
server 192.168.199.2:8089; | |
} | |
server { | |
listen 80; | |
server_name mydomain.com www.mydomain.com; | |
location / { | |
proxy_pass_header Server; | |
proxy_set_header Host $http_host; | |
proxy_redirect off; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Scheme $scheme; | |
proxy_pass http://frontends; | |
} | |
#静态资源交由nginx管理 | |
location /static { | |
root /var/www/mydomain/web; | |
expires 1d; | |
add_header Cache-Control public; | |
access_log off; | |
} | |
} | |
2.go程序试用http监听 | |
//this host ip 192.168.199.1 | |
func main() { | |
... | |
http.ListenAndServe(":8088", nil) | |
os.Exit(0) | |
} | |
... | |
//other | |
//this host ip 192.168.199.2 | |
func main() { | |
... | |
http.ListenAndServe(":8089", nil) | |
os.Exit(0) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment