nginx main application scenarios
1. Reverse proxy
(Recommended tutorial: nginx tutorial)
Reverse proxy should be the most common thing Nginx does. What is a reverse proxy? The following is what Baidu Encyclopedia says: The reverse proxy (Reverse Proxy) method refers to using a proxy server to accept the Internet. The connection request is then forwarded to the server on the internal network, and the result obtained from the server is returned to the client requesting the connection on the Internet. At this time, the proxy server appears as a reverse proxy server to the outside world. To put it simply, the real server cannot be directly accessed by the external network, so a proxy server is needed. The proxy server can be accessed by the external network and is in the same network environment as the real server. Of course, it may also be the same server and port. Just different.
Key command: proxy_pass; For example, transfer localhost port 80 to localhost port 8080
<span style="color: #000000;">server { listen 80; server_name localhost; location / { proxy_pass http://localhost:8080; proxy_set_header Host $host:$server_port; }<br>} </span>
2. Load balancing
Load balancing is also a commonly used function of Nginx. Simply put, when there are 2 or more servers, requests are randomly distributed to designated servers for processing according to rules. Load balancing configuration generally needs to be configured at the same time. Reverse proxy, jump to load balancing through reverse proxy. Nginx currently supports 3 built-in load balancing strategies, as well as 2 commonly used third-party strategies
Key commands: upstream; such as allocating requests from localhost port 80 to localhost 8080 and localhost 8081
Load scheme:
1), weight weight: session sharing must be implemented, otherwise the user session will be out of sync, causing the user to log in again
upstream test { server localhost:8080 weight=9; #请求的 90% 进入到8080服务器 server localhost:8081 weight=1; #请求的 10% 进入到8081服务器 }
2), ip_hash: Each request is allocated according to the hash result of the accessed IP, so that each visitor has a fixed access to a back-end server, which can solve the session problem
upstream test { ip_hash; server localhost:8080; server localhost:8081; }
3), fair (third party): press Requests are allocated based on the response time of the backend server, and those with shorter response times are allocated first.
upstream test { fair; server localhost:8080; server localhost:8081; }
4), url_hash (third party): Ask the hash result of the URL to allocate requests so that each URL is directed to the same back-end server. It is more effective when the back-end server is cached
upstream backend { hash $request_uri; hash_method crc32; server localhost:8080; server localhost:8081; }
5), Default: allocate to different machines at once according to time
upstream test { server localhost:8080; server localhost:8081; } server { listen 80; server_name localhost; client_max_body_size 1024M; location / { proxy_pass http://test; proxy_set_header Host $host:$server_port; } }
3, WEB server
Nginx itself is also a static resource server. When there are only static resources, You can use Nginx as a server. At the same time, it is also very popular now to separate static and dynamic resources, which can be achieved through Nginx. First, let’s take a look at Nginx as a static resource server.
In this way, if you access http://localhost, you will access it by default #index.html
under the ##E://www/data directory, if a website is just a static page, then it can be deployed in this way
root When there are only static resources, you can use Nginx as the server
server { listen 80; server_name localhost; location / { root e:/www/data; index index.html; } }4. Forward proxy does not support HTTPS
Forward proxy , meaning a server located between the client and the origin server (origin server). In order to obtain content from the origin server, the client sends a request to the proxy and specifies the target (origin server), and then the proxy forwards the request to the origin server and The obtained content is returned to the client. Only clients can use forward proxies. When you need to use your server as a proxy server, you can use Nginx to implement forward proxy, but currently Nginx has a problem, that is, it does not support HTTPS
upstream test{ server localhost:8080; server localhost:8081; } server { listen 80; server_name localhost; location / { root e:/wwwroot; index index.html; } # 所有静态请求都由nginx处理,存放目录为html location ~ .(gif|jpg|jpeg|png|bmp|swf|css|js)$ { root e:/wwwroot; } # 所有动态请求都转发给tomcat处理 location ~ .(do)$ { proxy_pass http://test; } error_page 500 502 503 504 /50x.html; location = /50x.html { root e:/wwwroot; } }
The above is the detailed content of What are the common application scenarios of nginx?. For more information, please follow other related articles on the PHP Chinese website!

本篇文章给大家带来了关于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禁止访问php的方法:1、配置nginx,禁止解析指定目录下的指定程序;2、将“location ~^/images/.*\.(php|php5|sh|pl|py)${deny all...}”语句放置在server标签内即可。

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


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

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 Linux new version
SublimeText3 Linux latest version

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!
