An example of nginx domain name redirection ~~~ Rewrite, proxy

Source: Internet
Author: User
: This article mainly introduces an example of nginx domain name redirection ~~~ Rewrite and proxy. if you are interested in PHP tutorials, refer. A few days ago, I set up a forum server and put it in the company's LAN. the Forum uses port 9066 and implements port forwarding on the router, in addition, the domain name bbs.xxx.com is also directed to the company's public IP address, because users want to make a jump on the company's web server without entering the port number during access, all requests to access bbs.xxx.com are forwarded to the server. My first thought was to use nginx rewrite. The process was simple and configured as follows:

Server {
Listen 80;
Server_name bbs.xxx.com;
Rewrite "^/(. *) $" http://bbs.xxx.com: 9066/$1 break;
}

So I accessed bbs.xxx.com and checked it. registration, logon and posting operations were normal. I thought it would be OK. Then the problem occurred, although it can jump normally, the address on the domain name bar of the user's browser is always followed by the port number 9066, which makes the leaders very dissatisfied, so I found nginx documents and asked other friends in the QQ group. there is no good solution. So we switched to proxy_pass. This configuration is also very simple:

Server {
Listen 80;
Server_name bbs.xxx.com;
Location/
{
Proxy_pass http://bbs.xxx.com: 9066 /;
}
}

The port number after accessing bbs.xxx.com is no longer available, and registration, logon, and posting are normal. However, a problem may occur in a short time. the user reports that the forum cannot be registered, the prompt says "a single ip address can only be registered five times a day". what is the problem? after checking the log, it is found that all requests sent from the public network are actually the ip address of the Gateway, now I understand that nginx will not judge the real client ip address if it is not further set after proxy is added, but will directly use the routing address as the request ip address, therefore, the above situation may occur. after analysis, I checked the nginx wiki and added several more on it:

Server {
Listen 80;
Server_name bbs.xxx.com;
Location/
{
Proxy_set_header Host $ host;
Proxy_set_header X-Real-Ip $ remote_addr;
Proxy_set_header X-Forwarded-For $ remote_addr;
Proxy_pass http://bbs.xxx.com: 9066 /;
}
}

After the change, reload nginx and find that the source ip address in the log is already the real client address. it is normal to re-register, log on, post, and repeat it multiple times, and no problem is found, the customer is also normal.

I would like to thank you for your enthusiastic help.

The following is an article from the Internet, analysis of a very detailed http://www.beijus.info /? P = 730 & cpage = 1. I also want to thank the author of this article, "egg noodle"

This article is from the "story of the sky" blog, please be sure to keep this source http://storysky.blog.51cto.com/628458/486338

The preceding section describes an example of nginx domain name redirection ~~~ Rewrite, proxy, including the content, hope to be helpful to friends interested in PHP tutorials.

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.