久久99国产精品片久久99蜜桃_久久精品99国产精品蜜桃_久久久亚洲AV成人网站_欧美精品色婷婷五月综合_亚洲精品乱码久久久久久蜜桃图片_夜夜高潮夜夜爽国产伦精品_69无人区乱码一二三四区别_日产一码二码三码区别_大香区一二三四区2021_国产精品爱久久久久久久,日本高清视频成人网www,国产亚洲一二三区精品免费视频观看,久久久精品国产SM调教网站

歡迎訪問分類目錄網(wǎng)
快審聯(lián)系QQ:158925126當前位置:分類目錄網(wǎng) » 站長資訊 » 技術(shù)教程 » 文章詳細 訂閱RssFeed

設置nginx的proxy_cache 網(wǎng)站緩存 詳細步驟

來源:網(wǎng)絡 瀏覽:865次 時間:2015-05-31
隨著網(wǎng)站流量的提升,,如果只是單臺機器既處理靜態(tài)文件,,又處理動態(tài)腳本,顯然效率很難上升,,不能處理日益上漲的流量壓力,。與此同時某些網(wǎng)站的頁面內(nèi)容并不是經(jīng)常變化,因此我們可以分兩層架構(gòu)來組織網(wǎng)站,。前端web緩存+后端web服務器,,可以參看這里配置nginx反向代理配置

前端web緩存有多重方式實現(xiàn),原理就是隊請求結(jié)果頁面靜態(tài)化并設置一個超時期限,,緩存頁面過期后,,新請求到達時重新到后端web服務器獲取內(nèi)容更 新;沒有nginx前比較流行的方法是squid,,但squid不能充分利用處理器的多核特性,,越來越多的網(wǎng)站選用nginx來做前端的web緩存。

要想使用nginx的緩存功能要保證nginx添加了proxy模塊,。我們可以使用-V選項(大寫的V,,小寫的v是看版本號的)來查看nginx的編譯參數(shù)。我使用的是默認的參數(shù)編譯的,,如下所示:

root@SNDA-172-17-12-117:/usr/local/nginx# ./nginx -V
nginx version: nginx/1.2.3
built by gcc 4.4.3 (Ubuntu 4.4.3-4ubuntu5.1)
TLS SNI support enabled
configure arguments: --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.21 --with-zlib=/usr/local/src/zlib-1.2.7

nginx的所有模塊必須在編譯的時候添加,,不能再運行的時候動態(tài)加載,,默認的編譯選項下包含的模塊,如果你不是顯示的用參數(shù)關閉它,。

nginx默認安裝的模塊如下

模塊名稱 描述 版本 如何禁用
Core Control ports, locations, error pages, aliases, and other essentials.
--without-http
Access Allow/deny based on IP address.
--without-http_access_module
Auth Basic Basic HTTP authentication.
--without-http_auth_basic_module
Auto Index Generates automatic directory listings.
--without-http_autoindex_module
Browser Interpret "User-Agent" string. 0.4.3 --without-http_browser_module
Charset Recode web pages.
--without-http_charset_module
Empty GIF Serve a 1x1 image from memory. 0.3.10 --without-http_empty_gif_module
FastCGI FastCGI Support.
--without-http_fastcgi_module
Geo Set config variables using key/value pairs of IP addresses. 0.1.17 --without-http_geo_module
Gzip Gzip responses.
--without-http_gzip_module
Headers Set arbitrary HTTP response headers.
Index Controls which files are to be used as index.
Limit Requests Limit frequency of connections from a client. 0.7.20 --without-http_limit_req_module
Limit Zone Limit simultaneous connections from a client. Deprecated in 1.1.8, use Limit Conn Instead. 0.5.6 --without-http_limit_zone_module
Limit Conn Limit concurrent connections based on a variable.
--without-http_limit_conn_module
Log Customize access logs.
Map Set config variables using arbitrary key/value pairs. 0.3.16 --without-http_map_module
Memcached Memcached support.
--without-http_memcached_module
Proxy Proxy to upstream servers.
--without-http_proxy_module
Referer Filter requests based on Referer header.
--without-http_referer_module
Rewrite Request rewriting using regular expressions.
--without-http_rewrite_module
SCGI SCGI protocol support. 0.8.42 --without-http_scgi_module
Split Clients Splits clients based on some conditions 0.8.37 --without-http_split_clients_module
SSI Server-side includes.
--without-http_ssi_module
Upstream For load-balancing.
--without-http_upstream_ip_hash_module (ip_hash directive only)
User ID Issue identifying cookies.
--without-http_userid_module
uWSGI uWSGI protocol support. 0.8.40 --without-http_uwsgi_module
X-Accel X-Sendfile-like module.

proxy模塊中常用的指令時proxy_pass和proxy_cache.

nginx的web緩存功能的主要是由proxy_cache,、fastcgi_cache指令集和相關指令集完成,proxy_cache指令負 責反向代理緩存后端服務器的靜態(tài)內(nèi)容,,fastcgi_cache主要用來處理FastCGI動態(tài)進程緩存(這里我不是很清楚這兩個指令的區(qū)別,,好像功能 上都差不多,尤其后面這句話的意思,,是我翻譯過來的),。

確認proxy模塊安裝好后,下面對nginx的配置文件進行設置,,重點部分如標紅字體所示,。

這是我的nginx.conf配置文件。

user www-data;
worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" "$host"';

#access_log logs/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#Compression Settings
gzip on;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_proxied any;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
# Some version of IE 6 don't handle compression well on some mime-types,
# so just disable for them
gzip_disable "MSIE [1-6].(?!.*SV1)";
# Set a vary header so downstream proxies don't send cached gzipped
# content to IE6
gzip_vary on;
#end gzip

#cache begin
proxy_buffering on;
proxy_cache_valid any 10m;
proxy_cache_path /data/cache levels=1:2 keys_zone=my-cache:8m max_size=1000m inactive=600m;
proxy_temp_path /data/temp;
proxy_buffer_size 4k;
proxy_buffers 100 8k;
#cache end

## Basic reverse proxy server ##
## Apache (vm02) backend for www.example.com ##
upstream apachephp {
server www.quancha.cn:8080; #Apache1
}

## Start www.quancha.cn ##
server {
listen 80;
server_name *.quancha.cn;

access_log logs/quancha.access.log main;
error_log logs/quancha.error.log;
root html;
index index.html index.htm index.php;

## send request back to apache1 ##
location / {
proxy_pass http://apachephp;
proxy_cache my-cache;
proxy_cache_valid 200;

#Proxy Settings
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_max_temp_file_size 0;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
##End Proxy Settings
}
}
## End www.quancha.cn ##

}

配置文件中以proxy_開頭的指令我們大都可以字面意思得到理解,。請務必注意一點proxy_cache_path和proxy_temp_path設置的目錄需要在同一分區(qū),,因為它們之間是硬鏈接的關系。

最后執(zhí)行重新加載nginx配置文件啟動nginx :/usr/local/nginx/sbin/nginx -s reload,,來迎接著激動人心的時刻吧,。

公司企業(yè)大全

推薦站點

  • 納米AI搜索 納米AI搜索

    納米AI搜索開創(chuàng)全新問答方式,,沒有套路,直接給答案,,讓搜索變得簡單直觀,!拍照問、語音搜,、聽

    www.n.cn
  • 一號屋手賺庫 一號屋手賺庫

    一號屋手賺庫致力于分享最新且免費的手機賺錢軟件,,在這里,你可以找到各種類型的賺錢app,,獲

    www.yihaowu.com
  • 事業(yè)編招聘網(wǎng) 事業(yè)編招聘網(wǎng)

    事業(yè)編招聘網(wǎng)(sybzp.cn)事業(yè)單位招聘信息基考試資料原創(chuàng)內(nèi)容網(wǎng)站,,主打快速、全面,、優(yōu)

    www.sybzp.cn
  • 4K高清電影下載 4K高清電影下載

    4Kfilm視界是專業(yè)的4K電影下載站,本網(wǎng)站頁面簡潔,提供4K盤HDR杜比視界電影,、美劇

    www.4kfilm.cn
  • 百評客 百評客

    百評客深度評測各種賺錢游戲、手機賺錢app,,提供客觀且真實的評測分析,,在這里,你可以更了解

    m.baike5.com
  • 優(yōu)質(zhì)設計素材 優(yōu)質(zhì)設計素材

    顏格視覺專注海外創(chuàng)意廣告設計圖片素材下載的網(wǎng)站,!提供包括樣機素材,平面素材,UI設計,ic

    www.youngem.com
  • 國家智慧教育平臺 國家智慧教育平臺

    國家智慧教育平臺,,全稱國家智慧教育公共服務平臺,,是由中華人民共和國教育部指導,教育部教育技

    www.smartedu.cn
  • 鳥說游戲 鳥說游戲

    鳥說是一個聚焦電競產(chǎn)業(yè)的網(wǎng)站,,旨在分享不一樣的電競樂趣,。我們致力于提供最新的電競資訊、熱門

    www.niaoshuo.com
  • 游軟盟 游軟盟

    游軟盟是一個免費的應用下載網(wǎng)站,,為用戶提供好玩的手機游戲,、實用的手機軟件下載,我們也會及時

    app.ufolm.com