Nginx Settings for Web caching

Source: Internet
Author: User

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.gz

wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz




Install/hcdata/software/pcre-8.37 First

./configure

Make && make install




./configure--user=www \
>--group=www \
>--prefix=/hcdata/server/nginx \
>--with-http_stub_status_module \

>--with-http_ssl_module \
>--with-http_gzip_static_module \
>--with-openssl=/usr/local/src/openssl-1.0.1c \
>--with-pcre=/hcdata/software/pcre-8.37 \
>--with-pcre-jit \
>--add-module=/hcdata/software/ngx_cache_purge-2.3

Make && make install


Then nginx.conf the cache of the configuration picture

Location ~.*\. (Gif|jpg|jpeg|png|bmp|swf|mp3|mp4|wmv|txt) $
{
Proxy_cache Cache_one;
Proxy_cache_valid 304 12h;
Proxy_cache_valid 301 302 1m;
Proxy_cache_valid any 1m;
Proxy_cache_key $host $uri$is_args$args;



Proxy_pass http://ip:8098;
Proxy_redirect off;
Proxy_set_header Host $host;
Proxy_set_header x-forwarded-for $remote _addr;
}


server {

Listen 8098;
server_name IP;
Location/{
root/hcdata/www;
AutoIndex on;
}


Proxy_pass must be paired with Proxy_cache, or the cache will not be implemented.


Add Purge:

Location ~/purge (/.*) {
Allow all;
Proxy_cache_purge Cache_one $host $1$is_args$args;

}


The 404 error occurs because this location is not placed in the

Location ~.*\. (Gif|jpg|jpeg|png|bmp|swf|mp3|mp4|wmv|txt) $ {

。。。。

} before


The correct order is:

server {
Listen 80;
server_name uadmin;

CharSet Utf-8;

#access_log Logs/host.access.log Main;



Location ~/purge (/.*) {
Allow all;
Proxy_cache_purge Cache_one $host $1$is_args$args;

}


Location ~.*\. (Gif|jpg|jpeg|png|bmp|swf|mp3|mp4|wmv|txt) $
{
Proxy_cache Cache_one;
Proxy_cache_valid 304 12h;
Proxy_cache_valid 301 302 1m;
Proxy_cache_valid any 1m;
Proxy_cache_key $host $uri$is_args$args;

# root/hcdata/www;
# AutoIndex on;

Proxy_pass http://*.*.*.*:8098;
Proxy_redirect off;
Proxy_set_header Host $host;
Proxy_set_header x-forwarded-for $remote _addr;
}



Location/{
# Proxy_cache Cache_one;
# proxy_cache_valid 304 12h;
# Proxy_cache_valid 301 302 1m;
# Proxy_cache_valid any 1m;
# Proxy_cache_key $host $uri$is_args$args;

Proxy_pass http://uadmin;
Proxy_redirect off;
Proxy_set_header Host $http _host;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
Proxy_set_header Connection Close;
Proxy_set_header x-forwarded-for $remote _addr;
Error_page 404/404.html;
Error_page 502 503 504/50x.html;
}
#error_page 404/404.html;

# REDIRECT Server error pages to the static page/50x.html
#
Error_page 502 503 504/50x.html;
Location =/50x.html {
root HTML;
}

# Proxy The PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# Proxy_pass http://127.0.0.1;
#}

# Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root HTML;
# Fastcgi_pass 127.0.0.1:9000;
# Fastcgi_index index.php;
# Fastcgi_param Script_filename/scripts$fastcgi_script_name;
# include Fastcgi_params;
#}

# Deny access to. htaccess files, if Apache ' s document Root
# concurs with Nginx ' s one
#
#location ~/\.ht {
# Deny All;
#}
}


# Another virtual host using mix of ip-, name-, and port-based configuration
#
#server {
# Listen 8000;
# Listen somename:8080;
# server_name somename alias Another.alias;

# location/{
# root HTML;
# index index.html index.htm;
#    }
#}

server {

Listen 8098;
server_name *.*.*.*;
Location/{
root/hcdata/www;
AutoIndex on;
}

}

Nginx Settings for Web caching

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.