Nginx cache static files (such as CSS JS) __js

Source: Internet
Author: User
Tags nginx server

Purpose: To cache the static files of the Nginx server. As css,js,htm,html,jpg,gif,png,flv,swf, these files are not updated frequently. Easy caching to ease server pressure.
Implementation: Nginxproxy_cache can cache the user's request to a local directory, when the next request can be directly transferred to the cache file, you do not have to go to the backend server to fetch files.
Configuration: Open configuration file/etc/nginx/nginx.conf

User www www.
Worker_processes 2;
Error_log/var/log/nginx/nginx_error.log Crit;
Worker_rlimit_nofile 65535;
Events
{
Use Epoll;
Worker_connections 65535;
}

http
{
Include Mime.types;
Default_type Application/octet-stream;

Server_names_hash_bucket_size 128;
Client_header_buffer_size 32k;
Large_client_header_buffers 4 32k;
Client_max_body_size 8m;

Sendfile on;
Tcp_nopush on;
Keepalive_timeout 0;
Tcp_nodelay on;

  fastcgi_connect_timeout 300;
  fastcgi_send_timeout 300;
  fastcgi_read_timeout 300;
  fastcgi_buffer_size 64k;
  fastcgi_buffers 4 64k;
  fastcgi_busy_buffers_size 128k;
  fastcgi_temp_file_write_size 128k;
  # #cache # #
  proxy_connect_timeout 5;
  proxy_read_timeout;
  proxy_send_timeout 5;
  proxy_buffer_size 16k;
  proxy_buffers 4 64k;
  proxy_busy_buffers_size 128k;
  proxy_temp_file_write_size 128k;
  proxy_temp_path/home/temp_dir;
  proxy_cache_path/home/cache levels=1:2keys_zone=cache_one:200m inactive=1d max_size=30g;
  # #end # #

gzip on;
Gzip_min_length 1k;
Gzip_buffers 4 8k;
Gzip_http_version 1.1;
Gzip_types text/plain application/x-javascript text/css application/xml;
Gzip_disable "MSIE [1-6]\.";

Log_format access ' $remote _addr-$remote _user [$time _local] ' $request '
' $status $body _bytes_sent ' $http _referer '
' $http _user_agent ' $http _x_forwarded_for ';
Upstream AppServer {
Server 192.168.1.251;
}
server {
Listen default;
server_name blog.slogra.com;
location~. *\. (gif|jpg|png|htm|html|css|js|flv|ico|swf) (.*) {
Proxy_pass Http://appserver;
Proxy_redirect off;
Proxy_set_header Host $host;
Proxy_cache Cache_one;
Proxy_cache_valid 302 1h;
Proxy_cache_valid 1d;
Proxy_cache_valid any 1m;
Expires 30d;
}
Location ~. *\. (PHP) (.*) {
Proxy_pass Http://appserver;
Proxy_set_header Host $host;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header

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.