Nginx: setting of a reverse proxy

Source: Internet
Author: User
Tags mdb database

In this case,

There is an application running ASP, which is relatively earthy and still uses a local *. mdb database. In this way, it is impossible to run the plug-in Apache: ASP in a Linux environment. It is also a pretty bad ASPProgram, Even HTML templates are not stored in separate directories and are directly mixed with *. asp.

Fortunately, this world has nginx, which is the best Optimization for such things.

If IIS is used to process both ASP and static files, the performance of traffic is unimaginable.
(In the AB stress test, testing on a GIF static file requested by 100 threads has made the IIS CPU quite uneasy)

The two servers run the architecture plan as the simplest nginx-> IIS

Use nginx proxy to access port 80 of IIS.

However, during the test, it was found that although the speed was instantly reflected, nginx would pull files, Especially static files, to IIS for each request.
Large, And it will upset the CPU of IIS.

Originally, I tried to mount an SMB disk in Linux and then asked nginx to directly request static files on the IIS application server through SMB. This avoids IIS pressure. But something strange .... It has nothing to do with this article.

Finally, nginx proxy_store is used. nginx directly creates and reads static files on the local hard disk,

The results are quite good, and to some extent, it is a little difficult to install squid for such a bad application.

But there is a difference between proxy_store and squid !! The most obvious difference is that it does not have expires and cannot control the cache expiration time through the program. I will write a script to regularly Delete the content in the cache directory, but that's exactly what I want.

The configuration method is as follows:

To Cache the file locally, add the following sub-parameters:
Proxy_store on;
Proxy_store_access User: RW group: RW all: RW;
Proxy_temp_path cache directory;

Where,
Proxy_store on enables the function of caching data locally,
Proxy_temp_path specifies the directory in which the cache is located, for example, proxy_temp_path/var/nginx_cache;

After configuration in the previous step, although the file is cached on the local disk, the file will be pulled from the remote end in each request. To avoid pulling files from the remote end, you must add:

If (! -E $ request_filename ){
Proxy_pass http: // 192.168.10.10;
}

If the requested file does not exist in the directory specified by the local proxy_temp_path, then the request is pulled from the backend.

Overall configuration example:

location ~. *\. (GIF | JPG | JPEG | PNG | BMP | SWF | JS | HTML | HTM | CSS) $ {# specify the cache file type
expires 7d; # Set the browser expiration time
root/data1/nginx_cache/IIS; # the root directory of the static file (which must correspond to proxy_temp_path)
proxy_store on; # enable the cache mechanism
proxy_store_access User: RW group: RW all: RW; # cache read/write rules
proxy_temp_path/data1/nginx_cache/IIS; # cache directory for storing static files
include proxy. conf; # detailed configuration of the external proxy, such as proxy_set_header, client_max_body_size ....
If (! -E $ request_filename) {# regular expression, matching the existence of files and source files in the cache directory)
proxy_pass http: // 192.168.10.10 # server address of the IIS application
}< BR >}

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.