Nginx Cache service configuration and load balancing

Source: Internet
Author: User
Keywords Load balancing service configuration Nginx
Tags access backup cache cached caching configuration directory file

Nginx Cache Service Configuration

If you need to cache files locally, you need to add the following sub parameters:

Proxy_store on;
Proxy_store_access USER:RW GROUP:RW ALL:RW;
Proxy_temp_path cache directory;

which,

Proxy_store on is used to enable caching to local functionality,

Proxy_temp_path is used to specify in which directory the cache is cached, such as: Proxy_temp_path html;

After the previous configuration, although the file is cached on the local disk, but each request will still pull the file to the remote, to avoid the remote pull file, you must modify the Proxy_pass:

if (!-e $request _filehttp://www.aliyun.com/zixun/aggregation/11696.html ">name") {
Proxy_pass Http://mysvr;
}

It is changed to conditionally execute Proxy_pass, which is when the requested file is not present in the directory specified by the local proxy_temp_path, and then pulled back.

More advanced applications can be studied Ncache, official website: http://code.google.com/p/ncache/
For detailed installation please refer to http://bbs.linuxtone.org application Accelerator version Ncache related posts.

Nginx Load Balancing

1. Nginx Load Balancing basic knowledge

Nginx's upstream currently supports 4 different ways of allocating

1), polling (default)

Each request is assigned to a different back-end server in chronological order, and can be automatically removed if the backend server is down.

2), Weight

Specifies the polling probability, proportional to the weight and the access ratio, for the performance of the backend server.

2), Ip_hash

Each request is allocated according to the hash result of the access IP, so that each visitor has a fixed access to a back-end server that resolves the session's problem.

3), Fair (third party)

The response time of the backend server is assigned to the request, and the response time is short.

4), Url_hash (third party)

2. Nginx Load Balancing Example 1

Upstream bbs.linuxtone.org {#定义负载均衡设备的Ip及设备状态
Server 127.0.0.1:9090 down;
Server 127.0.0.1:8080 weight=2;
Server 127.0.0.1:6060;
Server 127.0.0.1:7070 backup;
}

Increase in servers that need to use load balancing

Proxy_pass http://bbs.linuxtone.org/;

The status of each device is set to:

A) down indicates that the server before the order temporarily does not participate in the load

b weight The default is 1.weight larger, the load weight will be greater.

c) Max_fails: The number of allowed requests failed defaults to 1. Returns the error of the Proxy_next_upstream module definition when the maximum number of times is exceeded

D fail_timeout:max_fails time after failure.

E Backup: All other non-backup machines request backup machines when down or busy. So this machine will be the lightest pressure.

Nginx supports multiple sets of load balancing to be used for unused servers.

Client_body_in_file_only set to on can be used to speak the client post from the data log to the file to do debug

Client_body_temp_path sets the directory for logging files up to 3 levels

Location the URL. Can be redirected or new agent load balancing

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.