nginx做rails项目web服务器缓存配置方法
2015-11-30 09:40
731 查看
nginx作为Web服务器、或反向代理服务器都可以使用缓存
一、作为Web服务器
nginx可以通过 expires 指令来设置响应头的过期时间,实现浏览器缓存(Browser Caching),即浏览器在用户磁盘上对最近请求过的文档进行存储。
其中,下面两句是必须的。Passenger是一个Rails应用服务的管理工具,可以统一管理Rails进程的数量、生命周期、请求队列。root用来配置passenger所引导rails应用
完整配置信息
二、作为反向代理服务器
此时的缓存文件是保存到nginx所在的服务器,减少访问web服务器的次数,由nginx直接返回请求的信息,减小web服务器压力
一、作为Web服务器
nginx可以通过 expires 指令来设置响应头的过期时间,实现浏览器缓存(Browser Caching),即浏览器在用户磁盘上对最近请求过的文档进行存储。
其中,下面两句是必须的。Passenger是一个Rails应用服务的管理工具,可以统一管理Rails进程的数量、生命周期、请求队列。root用来配置passenger所引导rails应用
root /home/autotest/zhangs_trunk2015/public; passenger_enabled on;
完整配置信息
location / {
#root html;
#index index.html index.htm;
root /home/autotest/zhangs_trunk2015/public; passenger_enabled on;
}
location ~.*\.(jpg|png|jpeg|gif){
root /home/autotest/zhangs_trunk2015/public; passenger_enabled on;
expires max;
}
location ~(bootstrap.min.js|flat-ui.min.js|jquery.min.js|bootstrap.min.css|flat-ui.min.css|flat-ui-icons-regular.woff){
root /home/autotest/zhangs_trunk2015/public; passenger_enabled on;
expires 1d;
}
二、作为反向代理服务器
此时的缓存文件是保存到nginx所在的服务器,减少访问web服务器的次数,由nginx直接返回请求的信息,减小web服务器压力
http://appserver指web服务器的域名
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 60; 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 80 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 200 302 1h; proxy_cache_valid 301 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 X-Forwarded-For$proxy_add_x_forwarded_for; } access_log /var/log/nginx/blog.slogra.com.log; } }
相关文章推荐
- Ubuntu下安装Nginx
- nginx服务配置---php服务接入
- Nginx和lvs在负载均衡方面的对比
- nginx php-fpm 输出php错误日志
- Nginx代码风格图示
- Centos安装nginx
- nginx---别名(alias)在ci框架的应用
- Debian 7/Ubuntu14.04 LNMP环境搭建
- wordpress 图片裁剪问题处理
- nginx+ngrok的配置
- Nginx配置文件nginx.conf中文详解(汇总)
- nginx的安装及配置
- nginx做mail proxy 的时候,把消息proxy到哪里去了 4000
- nginx 基本配置
- 开启reuse_port让Tengine性能提升3倍
- LVS Nginx HAProxy 优缺点
- Nginx配置
- Nginx安装--2015.11.27
- centos中安装nginx详细步骤
- mac ox 10.11 brew安装Nginx+PHP+MySQL+扩展