Nginx Domain name Jump a case ~~~rewrite, proxy

Source: Internet
Author: User
A few days ago set up a forum server and put in the company's local area network, the forum is used 9066 Portsand a port forwarding on the router, and bbs.xxx.com This domain also points to the company's public network IP, because you want to let users do not enter the port number when accessingSo I want to do a jump on the company's Web server, the request to access bbs.xxx.com to his server. My first idea is to use Nginx rewrite, the process is very simple configuration as follows:

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

So visit bbs.xxx.com Check, registration, login post and so on operation are normal, this thought so OK, the result then problem appeared, although can normal jump but user browser domain name bar address followed by 9066 this port number, This makes the leadership very dissatisfied, so I find the next Nginx document and QQ Group asked the next friend, there is no good way. So instead of Proxy_pass, this configuration is simple:

server {
Listen 80;
server_name bbs.xxx.com;
Location/
{
Proxy_pass http://bbs.xxx.com:9066/;
}
}

Then visit bbs.xxx.com after the port number is not, registration, login, post are normal, but not for a while, the user reflects the forum can not register, the hint that " single IP can only register 5 times a day ", this is how to go through the log after detection All the public network sent over the request is the IP address of the gateway, which I understand the simple add a proxy later if not further set the words Nginx will not judge the real client IP, but directly the address of the route as the request IP, so the above situation will appear, the analysis after the next The Nginx wiki then adds several more to 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 a bit nginx, found that the source IP in the log is the real client address, re-registration, login, post, are normal, repeated a number of times did not find the problem, customers there are normal.

Thank you for helping me with the three-door teeth.

Here is an article from the Internet, the analysis of a very detailed http://www.beijus.info/?p=730&cpage=1, but also thank the author of the article "Egg noodle"

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

The above describes the Nginx domain name jump An example ~~~rewrite, proxy, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    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.