如何为微服务设计Nginx位置? [英] How to design Nginx location for microservice?
问题描述
我们有10个基于微服务的应用程序.他们每个人都有大约15个服务.因此,我们为产品提供了150个不同的服务URL.
我的问题:如何设计Nginx位置?
1)每个应用程序一个位置
2)每个网址一个位置
3)其他方式
我认为需要权衡取舍.
a.配置复杂度
b.冲突位置问题
c.微服务重构时的情感
d. nginx.conf大小有人可以给我一些指导或最佳做法吗?
仅举一个我自己的配置示例.我不能说这是最好的方法,但是在整理之前,我确实参考了很多博客.
worker_processes 1;
events { worker_connections 10000; }
http {
sendfile on;
gzip on;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 999;
gzip_disable "MSIE [1-6]\.";
gzip_types text/plain text/xml text/css
text/comma-separated-values
text/javascript
application/x-javascript;
# List of application servers
upstream company_api_servers {
server company.xxxx.xxxx:port_number;
}
upstream community_api_servers {
server community.xxxx.xxxx:port_number;
}
upstream devices_api_servers {
server devices.xxxx.xxxx:port_number;
}
# Configuration for the server
server {
# Running port
listen 80;
# Proxying the Companies API
location /companies {
proxy_pass http://company_api_servers;
proxy_redirect off;
proxy_set_header Host $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-Host $server_name;
}
# Proxying the Communities API
location /communities {
proxy_pass http://community_api_servers;
proxy_redirect off;
proxy_set_header Host $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-Host $server_name;
}
# Proxying the Devices API
location /devices {
proxy_pass http://devices_api_servers;
proxy_redirect off;
proxy_set_header Host $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-Host $server_name;
}
}
}
We have 10 Microservices-based applications. Each of them has about 15 services. So, we have 150 different service URLs for our product.
My question: How to design the Nginx location?
1) One location per application
2) One location per URL
3) Other way
I thinks there are something to trade off.
a. config complexity
b. conflict location issue
c. affection when micro-service refactor
d. nginx.conf size
Could someone give me some guidance or the best practice?
Just to give you an example of one of my own configuration. I cannot say this is the best way to do it, but I did refer/read a lot of blogs before making this up.
worker_processes 1;
events { worker_connections 10000; }
http {
sendfile on;
gzip on;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 999;
gzip_disable "MSIE [1-6]\.";
gzip_types text/plain text/xml text/css
text/comma-separated-values
text/javascript
application/x-javascript;
# List of application servers
upstream company_api_servers {
server company.xxxx.xxxx:port_number;
}
upstream community_api_servers {
server community.xxxx.xxxx:port_number;
}
upstream devices_api_servers {
server devices.xxxx.xxxx:port_number;
}
# Configuration for the server
server {
# Running port
listen 80;
# Proxying the Companies API
location /companies {
proxy_pass http://company_api_servers;
proxy_redirect off;
proxy_set_header Host $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-Host $server_name;
}
# Proxying the Communities API
location /communities {
proxy_pass http://community_api_servers;
proxy_redirect off;
proxy_set_header Host $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-Host $server_name;
}
# Proxying the Devices API
location /devices {
proxy_pass http://devices_api_servers;
proxy_redirect off;
proxy_set_header Host $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-Host $server_name;
}
}
}
这篇关于如何为微服务设计Nginx位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!