实用的nginx配置方法(负载均衡,微服务网关,静态html)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jinsedeme0881/article/details/79260802

1 后台服务以及负载均衡

  #设定负载均衡的服务器列表
  upstream myserver {
      #weigth参数表示权值,权值越高被分配到的几率越大
      
      server localhost:8102  weight=5;
      server localhost:8101  weight=5;
  }


2 server定义

server
  {
    listen 80;#监听端口
    server_name localhost;#域名
    index index.html index.htm index.php;
    #前端页面的存放目录
	root /usr/local/saas/front;
      location ~ .*\.(htm|html)?$
    {
      
    }

	# 所有以service开头的都转发给服务网关
	location /service/ {
		 proxy_pass http://myserver/;  
	}

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$
    {
      expires 30d;
      access_log off;
    }
    location ~ .*\.(js|css)?$
    {
      expires 15d;
      access_log off;
    }
    access_log off;
  }


猜你喜欢

转载自blog.csdn.net/jinsedeme0881/article/details/79260802