background
Under current SpringCloud micro-service architecture, as the entrance gateway service is particularly important, once the gateway single point of failure can cause paralysis of the entire cluster service, in order to ensure high availability gateway can achieve high availability gateway through Nginx reverse proxy functionality.
Project Source: https://github.com/taoweidong/Micro-service-learning/tree/SpringCloud-branch
Project Chart
- Nginx as a reverse proxy server, back-end proxy gateway services, forwarded through the built-in load balancing algorithm Nginx
- Zull gateway cluster deployment, if a server fails, it will be forwarded to another machine, normal access service to ensure high availability gateway
Specific arrangements
Modifying the local Host file
(C: \ Windows \ System32 \ drivers \ etc) to edit the following file, modify the corresponding inside ip address, because to achieve reverse proxy to use a different domain name.
Nginx configuration
download
Nginx Download (Windows and Linux configuration as): http://nginx.org/en/download.html
Configuration
After decompression, find the configuration file \ nginx-1.12.2 \ conf \ nginx.conf
detailed configuration
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
#配置上游服务器网关端口集群
upstream backServer{
# weight 权重:谁的的权重多,访问到哪个服务的几率就大
server 127.0.0.1:8040 weight=1;
server 127.0.0.1:8041 weight=1;
}
server {
# 注意:如果使用域名进行反向代理的话,Nginx的端口必须是80
listen 80;
# 入口地址-对应域名地址
server_name www.taowd123.com;
location /ms {
### 指定上游服务器负载均衡服务器
proxy_pass http://backServer/;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
# 错误页面
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
test
- Start Registry Services: http://127.0.0.1:8761/
- Start two gateway ports are: 8041,8040
- Start service providers, port: 9000 has been configured in the Zuul
- Start Nginx Service
- Access registry inspection services
- Use a gateway port for direct access to normal
- The domain host configured using direct access, reverse proxy function test
access times, background checks gateway output
reference
https://blog.csdn.net/kxj19980524/article/details/87868108
Welcome to the personal blog: http://www.taoweidong.com/