Home > Backend Development > PHP Tutorial > An example of nginx domain name jump~~~rewrite, proxy

An example of nginx domain name jump~~~rewrite, proxy

WBOY
Release: 2016-07-29 09:02:33
Original
959 people have browsed it

A few days ago, I set up a forum server and put it in the company's LAN. The forum used port 9066 and made a port forwarding on the router, and pointed the domain name bbs.xxx.com to the company's public domain. Network IP,Because I don’t want users to enter the port number when accessing, I want to make a jump on the company’s web server and transfer all requests to access bbs.xxx.com to his server. My first thought was Using nginx's rewrite, the process is very simple. The configuration is as follows:

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

So visit bbs I checked .xxx.com and found that all operations such as registration, login and posting were normal. I thought it would be ok, but then a problem occurred. Although it could jump normally, the address on the domain name bar of the user's browser kept following. 9066 This port number made the leader very dissatisfied, so I looked for nginx documentation and asked other friends in the QQ group, but there was no good solution. So I used it instead proxy_pass, this configuration is also very simple:

server {
listen     80;
server_name bbs.xxx.com;
  location /
                                                                                           
         }
}

Then visit bbs.xxx.com and the port number behind it is no longer there. Registration, login, and posting are all normal, but a problem occurs again after a while. Users report that the forum cannot be registered, and the prompt says "

Single IP within one day You can only register 5 times", what happened, I found out after checking the logs All requests sent from the public network turned out to be the IP address of the gateway. Now I understood that after simply adding proxy, if there is no further setting, nginx will not judge the real client IP, but will directly add it. The routing address is used as the request IP, so the above situation will occur. After analysis, I checked the nginx wiki and added a few more entries:

server {listen 80;
server_name bbs.xxx.com;
location /
                            proxy_set_header       Host $host;
        proxy_set_header                            066/;
                                                           
After the modification, I reloaded nginx and found that the source IP in the log was already the real client address. Re-registration, login, and posting were all normal. After repeating it many times, no problem was found, and everything was normal at the customer's end.

Thanks to Sanmen Diesel for providing me with enthusiastic help.

The following is an article I found on the Internet. The analysis is very detailed http://www.beijus.info/?p=730&cpage=1. I also want to thank the author of this article "Dandan Noodles"

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

The above introduces an example of nginx domain name jump~~~rewrite and proxy, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template