码迷,mamicode.com
首页 > 其他好文 > 详细

Mastering Nginx 读书笔记二

时间:2015-10-30 15:33:55      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:nginx

NGINX as a Reverse Proxy


A reverse proxy is a web server that terminates connections with clients and

makes new ones to upstream servers on their behalf. An upstream server is

defined as a server that NGINX makes a connection with in order to fulfill the

client‘s request.



The most important directive when proxying to an upstream server is the  proxy_

pass directive. This directive takes one parameter—the URL to which the request

should be transferred. Using  proxy_pass with a URI part will replace the  request_

uri with this part. For example,  /uri in the following example will be transformed

to  /newuri when the request is passed on to the upstream:

请求的uri的部分将会被proxy_pass 后面的URL的uri部分替换,然后传递到上游服务器

location /uri {

proxy_pass http://localhost:8080/newuri;

}



There are two exceptions to this rule, however. First, if the location is defined

with a regular expression, no transformation of the URI occurs. In this example,

the URI  /local will be passed directly to the upstream, and not be transformed

to  /foreign as intended:

location 是正则匹配的话,请求的uri不会被转换,然后传递到上游服务器

location ~ ^/local {

proxy_pass http://localhost:8080/foreign;

}

The second exception is that if within the location a rewrite rule changes the URI,

and then NGINX uses this URI to process the request, no transformation occurs.

In this example, the URI passed to the upstream will be  /index.php?page=<match> ,

with  <match> being whatever was captured in the parentheses, and not  /index , as

indicated by the URI part of the  proxy_pass directive:

location中包含重写规则的话,就是用重写规则的uri,不会被proxy_pass 转换,然后传递到上游服务器

location / {

rewrite /(.*)$ /index.php?page=$1 break;

proxy_pass http://localhost:8080/index;

}




本文出自 “Linux is belong to you” 博客,请务必保留此出处http://jwh5566.blog.51cto.com/7394620/1708067

Mastering Nginx 读书笔记二

标签:nginx

原文地址:http://jwh5566.blog.51cto.com/7394620/1708067

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!