Nginx Processing Web Request analysis

Source: Internet
Author: User

First, the domain-based virtual server

Nginx first determines which server domain to use to process the request, and the following example has 3 virtual servers listening on the *:80 port.


server { listen 80; server_name nginx.org www.nginx.org; ... } server { listen 80; server_name nginx.net www.nginx.net; ... } server { listen 80; server_name nginx.com www.nginx.com; ...

}

在上面的配置中,nignx会根据HTTP请求“Host”的值,确定具体哪一个server接收web请求。如果“Host”不存在或者Host的值无法匹配任何sever中的$server_name,nginx就会把web请求送到默认的server中。如果没有定义default_server,默认将请求传递给第一个server。

默认server的配置方法如下:

server {      listen       80  default_server;      server_name  nginx.net  www.nginx.net;      ...

}

Second, the processing of IP and domain-based virtual host server {      listen       192.168.1.1:80;      server_name  nginx.org  www.nginx.org;      ... } server {      listen       192.168.1.1:80;      server_name  nginx.net  www.nginx.net;      ... } server {      listen       192.168.1.2:80;      server_name  nginx.com  www.nginx.com;      ... }

上面的配置中,nginx首先匹配IP地址和端口,然后在确定响应IP下的server_name,如果没有找到任何匹配的server_name,ngixn将请求传递给默认server。例如,当nginx收到来自 192.168.1.1:80 端口的请求www.nginx.com(无法匹配192.168.1.1下的任何一个server_name),The default server is not defined in the previous example, and the request is passed to the first server.

The default server configuration method is as follows:

Note: Nginx can define multiple default servers for different IP addresses and ports

eg

server {      listen        192.168.1.1:80;      server_name   nginx.org  www.nginx.org;      ... } server {      listen        192.168.1.1:80  default_server;      server_name   nginx.net  www.nginx.net;      ... } server {      listen        192.168.1.2:80  default_server;      server_name   nginx.com  www.nginx.com;      ...

}

Iii. How to handle PHP requests

I want to add .....






Nginx Processing Web Request analysis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.