How to configure Mod_proxy reverse proxy in a nginx server _nginx

Source: Internet
Author: User
Tags nginx server

Reverse proxy practices can be more than a step for the safety of the site, like some banks must be using the agent is you go into the proxy server can not get any data, the following I introduce nginx with mod_proxy implementation of reverse proxy configuration method.

Because the project needs to implement the function of a domain name agent
Like what:

Copy Code code as follows:
A.com/a.html=>b.com/b.html

That is, using the a.com agent of the use of B.Com Web site request, after a friend introduction with Apache reverse agent can achieve its purpose, the man tried, really cool. It is also extremely convenient to configure.

(Note the following only the reverse proxy, forward to the agent and so I used to introduce hehe)

1. Launch the Apache Mod_proxy module.

Copy Code code as follows:
LoadModule Proxy_module modules/mod_proxy.so
LoadModule Proxy_http_module modules/mod_proxy_http.so

Pay attention to mod_proxy_http.so. I did not add this module to test the agent failed, then the problem disappeared after adding this module

2. Implement the proxy statement

Copy Code code as follows:
proxypass/mirror/foo/http://backend.example.com/

Implement to distribute all requests below the current host/mirror/foo/directory to backend.example.com.
According to my request:
Add a section to the A.com folder directory

Copy Code code as follows:
proxypass/http://b.com/

Everything OK

3. After the domain name agent should note:
3.1: URLs in the Web site are best used relative paths. If you use an absolute path to bypass the proxy, then the host behind the proxy server is exposed easily.
3.2: Note that when referencing the $__server[' server_name '] global variable, the domain name of the current server_name is taken. If you want to take the proxy's domain name, pass $__server[' http_x_forwarded_for ' Get the proxy domain name. Note: Generally used to write cookies and such operations

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.