如果可以减少过多的外部隔离的API和简化部署的细节 这会是非常好的。
在以前的文章中,我解释了"一些使用反向代理的好处"。在我目前的项目里,我们已经构建分布式面向服务的架构,也显式提供了一个HTTP API,我们使用反向代理将请求路由通过API路由给单个组件。我们选择了Nginx Web这个优秀的服务器作为我们的反向代理,它快速、可靠且易于配置。我们通过它将多个HTTP的API服务聚合到一个URL空间。举例来说,当你键入:
http://api.example.com/product/pinstripe_suit
它将被路由到:
http://10.0.1.101:8001/product/pinstripe_suit
但当你访问:
http://api.example.com/customer/103474783
它将被路由到:
http://10.0.1.104:8003/customer/103474783
对使用者来言,他们觉得是在使用同一个URL空间(http://api.example.com/blah/blah),但在后端不同的顶级分类的URL被路由到不同的后端服务器。 /prodect/...路由到 10.0.1.101:8001, /customer/…则路由到10.0.1.104:8003。 我们也希望这是自动配置。比如说我想创建一个新的组件来记录的库存水平。相比于扩展现有的组件,我更希望能够写另一个独立的可执行文件或提供服务的HTTP端点,然后自动部署成为我的云计算基础架构中的主机之一,并使Nginx的自动将http ://api.example.com/sock/whatever 路由我新组件。 我们也想进行 后端服务的负载平衡,我们也想部署我们的股票 新API的多个服务实例间的Nginx自动轮询。
我们称每个顶级分类(/stock、/produck、/customer)为一个声明。 A组件上线时通过RabbitMQ发布了一个'AddApiClaim'。此消息有3个字段:'声明','IP地址','端口地址'。我们有一个'ProxyAutomation'的特殊组件,这个组件接收这些消息并按要求重写Nginx配置项。它使用SSH和SCP登录到nginx服务器,传输各种配置文件,并指示Nginx的重新加载配置。我们使用the excellent SSH.NET库来进行自动化。
Nginx的配置是一个非常好的事情是支持通配符。看一看我们的顶级配置文件:
...
http {
include /etc/nginx/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 /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
include /etc/nginx/conf.d/*.conf;
}
如16行所描述, 将conf.d目录的所有.conf引用到此处.
在conf.d文件夹内,有一个文件包含了所有api.example.com的请求配置:
include /etc/nginx/conf.d/api.example.com.conf.d/upstream.*.conf;
server {
listen 80;
server_name api.example.com;
include /etc/nginx/conf.d/api.example.com.conf.d/location.*.conf;
location / {
root /usr/share/nginx/api.example.com;
index index.html index.htm;
}
}
这段配置让 Nginx 侦听来自 80 端口的 api.example.com 的请求。
这里包括两部分。第一个部分是第一行,我将在以后讨论。第7行表述了将子目录"api.example.com.conf.d"中的location.*.conf引用到配置中来。我们代理服务器的自动化组件添加新的组件(AKA API claims)通过引入新的location.*.conf。举个例子,我们的股票组件可能创建一个location.stock.conf配置文件,像这样:
location /stock/ {
proxy_pass http://stock;
}
这只是简单的告诉Nginx将所有api.example.com/stock/…的代理请求转发到'stock'中定义的后端服务器,这些定义存放在'upstream.*.conf'中。代理自动化组件也引入了一个名为upstream.stock.conf文件,它看起来像这样:
upstream stock {
server 10.0.0.23:8001;
server 10.0.0.23:8002;
}
这些配置告诉Nginx将所有到api.example.com/stock/的请求轮询到给定的地址,在这个例子中两个实例在同一台机器(10.0.0.23)上,一个在8001端口,一个在8002端口。
正如股票组件的部署一样,添加新条目可以同样增加到upstream.stock.conf中。同样,当组件卸载时,只要删除对应条目就可以了,当所有组件移除时,将整个文件已就删除。
这种基础架构可以让我们聚合组件的基础设备。我们可以 通过简单地添加新的组件实例来扩展应用程序。作为组件开发人员也不需要做任何代理配置,只需要确保组件发送了添加或删除API声明的消息就可以了。

本篇文章给大家带来了关于nginx的相关知识,其中主要介绍了nginx拦截爬虫相关的,感兴趣的朋友下面一起来看一下吧,希望对大家有帮助。

高并发系统有三把利器:缓存、降级和限流;限流的目的是通过对并发访问/请求进行限速来保护系统,一旦达到限制速率则可以拒绝服务(定向到错误页)、排队等待(秒杀)、降级(返回兜底数据或默认数据);高并发系统常见的限流有:限制总并发数(数据库连接池)、限制瞬时并发数(如nginx的limit_conn模块,用来限制瞬时并发连接数)、限制时间窗口内的平均速率(nginx的limit_req模块,用来限制每秒的平均速率);另外还可以根据网络连接数、网络流量、cpu或内存负载等来限流。1.限流算法最简单粗暴的

实验环境前端nginx:ip192.168.6.242,对后端的wordpress网站做反向代理实现复杂均衡后端nginx:ip192.168.6.36,192.168.6.205都部署wordpress,并使用相同的数据库1、在后端的两个wordpress上配置rsync+inotify,两服务器都开启rsync服务,并且通过inotify分别向对方同步数据下面配置192.168.6.205这台服务器vim/etc/rsyncd.confuid=nginxgid=nginxport=873ho

nginx php403错误的解决办法:1、修改文件权限或开启selinux;2、修改php-fpm.conf,加入需要的文件扩展名;3、修改php.ini内容为“cgi.fix_pathinfo = 0”;4、重启php-fpm即可。

跨域是开发中经常会遇到的一个场景,也是面试中经常会讨论的一个问题。掌握常见的跨域解决方案及其背后的原理,不仅可以提高我们的开发效率,还能在面试中表现的更加

nginx部署react刷新404的解决办法:1、修改Nginx配置为“server {listen 80;server_name https://www.xxx.com;location / {root xxx;index index.html index.htm;...}”;2、刷新路由,按当前路径去nginx加载页面即可。

linux版本:64位centos6.4nginx版本:nginx1.8.0php版本:php5.5.28&php5.4.44注意假如php5.5是主版本已经安装在/usr/local/php目录下,那么再安装其他版本的php再指定不同安装目录即可。安装php#wgethttp://cn2.php.net/get/php-5.4.44.tar.gz/from/this/mirror#tarzxvfphp-5.4.44.tar.gz#cdphp-5.4.44#./configure--pr

nginx禁止访问php的方法:1、配置nginx,禁止解析指定目录下的指定程序;2、将“location ~^/images/.*\.(php|php5|sh|pl|py)${deny all...}”语句放置在server标签内即可。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),