
This is probably the brownest but most useful Nginx reverse proxy tutorial you've ever seen!
Reverse proxy to engage in load balancing this thing, with the opening of a hot pot restaurant to find the preparation of food master a reason. If you can't cut the vegetables in the kitchen, get a few more chefs to take turns chopping the meat. Nginx is the foreman who assigns tasks, but if the foreman himself is tired, the whole store has to stop. Today, we will use ipipgo proxy IP as a board master, teach you how to make the foreman both labor-saving and can withstand the peak period.
Basic Configuration: Reverse Proxy is Not Just a Different Vest
Many newbies think that changing a proxy_pass parameter even if the reverse proxy, which is like a hot pot restaurant back kitchen hanging a "central kitchen" sign. In order to really carry the traffic, you have to remember the three most important parameters:
| parameters | value of a person's life | life-preserving value |
|---|---|---|
| proxy_connect_timeout | Default 60s | 5s |
| proxy_read_timeout | Default 60s | 15s |
| proxy_send_timeout | Default 60s | 15s |
When hooking up ipipgo's proxy IP pool, it is recommended to add theproxy_next_upstreamConfiguration. For example, automatically switching to the next node when an IP node responds with more than 500 status codes is a life-saving trick.
IP pool management: don't put your eggs in one basket
I've seen too many people use proxy IPs as disposable chopsticks and throw them away when they're done. ipipgo's residential IP pool has 90 million + resources, but you have to be able to feed the fish:
1. Dynamic IP rotation period do not fool by the minute, according to the business peak settings
2. Static IP should do regular health checks, don't wait for things to go wrong before you realize it!
3. Different regions IP separate management, like Northeast pickles and Chongqing hot pot can not be stewed in one pot
It is recommended to use Nginx'smap moduleDo IP grouping to separate the scheduling of nodes in different countries of ipipgo. For example, European nodes specialize in image requests and American nodes handle video streams.
Connection optimization: don't let the foreman run the gauntlet
Nginx's default short-connection mode is like making the foreman run to the back kitchen for every dish he passes. Adding these two parameters immediately saves effort:
keepalive 32; //number of long connections maintained keepalive_timeout 60s; //connection keepalive timeout
Note that it has to be the same as the ipipgo proxy node'sMaximum concurrencyMatch. If the node can only carry 20 concurrency, setting 32 here is a death wish.
Caching strategy: a good memory is better than a bad one
Reverse proxy caching is not just a matter of opening a proxy_cache, it's a matter of posture:
- Dynamic content: set 5 seconds short cache + validation header
- Static resources: hierarchical caching based on file types
- Key data: using memcached for L2 caching
With ipipgo'sProtocol Supportfeature that caches certificate validation for HTTPS requests can save 30% handshake time.
Disaster recovery: leave a way out for New Year's Eve
The dumbest operation I've ever seen is a node hanging and desperately trying to retry. Configurationfusion mechanismIt's important:
1. Failure rate exceeding 201 TP3T automatic node isolation
2. Automatic resurrection of quarantined nodes after 30 minutes
3. Keep the standby node of 10% inactive during normal times
With ipipgo.API to get nodes dynamicallyfeature that allows updating the upstream list in real time, much more flexible than writing it to death in a configuration file.
QA Session: The Pitfalls Newbies Must Step Into
Q: What should I do if I always encounter 502 error?
A: Ninety percent is the proxy node timeout, first check the response time of the ipipgo node, and then adjust Nginx proxy_read_timeout
Q: How to choose between dynamic IP and static IP?
A: static for session maintenance, dynamic for crawlers. ipipgo supports both, and you can mix and match!
Q: Why can't I get my concurrency up?
A: 80% is not adjusted worker_connections, the value should be greater than the maximum number of concurrency. Remember to change the ulimit at the system level.
In the end, the reverse proxy to play well, three points rely on the configuration, seven points to see the quality of the proxy. ipipgo's residential IP pool natural anti-blocking, with reasonable Nginx configuration, which is to carry the high concurrency of the king of the bomb combination. Those who use data center IP still complain about being blocked, most likely do not understand the meaning of residential proxy.

