access

package
v0.0.0-...-d31700d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2022 License: MIT Imports: 14 Imported by: 0

README

基于Nginx的接入层(负载均衡)

x使用Nginx作为接入层和负载均衡。release/access.conf.tmpl是Nginx配置的模板文件,可以根据你的需求修改。x根据该模板生成Nginx配置。 使用如下命令可查看生成的nginx配置。

MacBook:~/go/src/example$ x access
upstream example-dev-app {
  server 127.0.0.1:3001;
  server 127.0.0.1:4001;
  keepalive 1;
}
upstream example-dev-web {
  server 127.0.0.1:8001 fail_timeout=3m;
  keepalive 1;
}
server {
  listen 80;
  server_name example.dev.example.com;
  
  location = / {
    proxy_pass http://example-dev-web;
  }
  location ~ \.(html|js|css|png|gif|jpg|svg|ico|woff|woff2|ttf|eot|map|json)$ {
    proxy_pass http://example-dev-web;
  }
  location / {
    proxy_pass http://example-dev-app;
  }

  proxy_http_version 1.1;
  proxy_set_header Connection "";
  proxy_set_header Host $http_host;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header X-Forwarded-Proto $scheme;
  proxy_connect_timeout 3s;

  access_log /var/log/nginx/example.dev.example.com/access.log;
  error_log  /var/log/nginx/example.dev.example.com/access.err;
}

使用x access setup命令则可以将Nginx配置写到接入层机器的/etc/nginx/sites-enabled/<domain>这个文件内,并且重新加载Nginx配置。

  1. release/clusters.yml文件中labels.accesstrue的机器就是需要配置接入层的机器。
  2. 重新加载Nginx配置通过执行 sudo nginx -s reload 命令来完成。
  3. Ubuntu的Nginx的主配置文件默认包含include /etc/nginx/sites-enabled/*;这条配置,所以/etc/nginx/sites-enabled目录下的所有配置文件都会生效。其他Linux发行版,如果没有这条配置,需要自行添加。
  4. 其中<domain>代表项目的域名,在release/img-app/config/config.yml配置文件中配置。
ubuntu@ubuntu:~/go/src/example$ x access setup
2018/08/11 17:41:00 ubuntu@127.0.0.1
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

使用x access reload命令来重新加载接入层机器的Nginx配置。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cmd

func Cmd() *cobra.Command

access commands

func HasAccess

func HasAccess(svcs []string) bool

func ReloadNginx

func ReloadNginx(env, feature string) error

func SetupNginx

func SetupNginx(env, feature, downAddr string) error

Types

type Config

type Config struct {
	AccessName string
	*config.Config
	App, Web *service
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL