2012-08-29 6 views
0

시작하려면, 저는 nginx를 처음 사용합니다.Nginx - Wordpress의 W3 캐싱 규칙

저는 gzip 압축 및 브라우저 캐싱 규칙을 Wordpress 사이트를 호스팅하는 일련의 Nginx 서버에 구현하려고합니다. 나는 nginx.conf 파일에 넣어하도록되어 다음 페이지에서 코드를 가지고 : http://codex.wordpress.org/Nginx

W3 총 캐시 규칙

# BEGIN W3TC Browser Cache 
gzip on; 
gzip_types text/css application/x-javascript text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon; 
location ~ \.(css|js)$ { 
    expires 31536000s; 
    add_header Pragma "public"; 
    add_header Cache-Control "max-age=31536000, public, must-revalidate, proxy-revalidate"; 
    add_header X-Powered-By "W3 Total Cache/0.9.2.3"; 
} 
location ~ \.(html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml)$ { 
    expires 180s; 
    add_header Pragma "public"; 
    add_header Cache-Control "max-age=180, public, must-revalidate, proxy-revalidate"; 
    add_header X-Powered-By "W3 Total Cache/0.9.2.3"; 
} 
location ~ \.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|swf|tar|tif|tiff|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$ { 
    expires 31536000s; 
    add_header Pragma "public"; 
    add_header Cache-Control "max-age=31536000, public, must-revalidate, proxy-revalidate"; 
    add_header X-Powered-By "W3 Total Cache/0.9.2.3"; 
} 
# END W3TC Browser Cache 
# BEGIN W3TC Skip 404 error handling by WordPress for static files 
if (-f $request_filename) { 
    break; 
} 
if (-d $request_filename) { 
    break; 
} 
if ($request_uri ~ "(robots\.txt|sitemap(_index|[0-9]+)?\.xml(\.gz)?)") { 
    break; 
} 
if ($request_uri ~* \.(css|js|html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml|asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|swf|tar|tif|tiff|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$) { 
    return 404; 
} 
# END W3TC Skip 404 error handling by WordPress for static files 

나는 http { 섹션에 배치 시도하고 다시 시작 서버가 있지만 위치가 잘못되었다고 말했습니다.

server {에 들어가야합니까? 또는 이것을 넣을 수있는 가장 좋은 장소는 무엇입니까?

감사합니다.

답변

1

http://nginx.org/en/docs/http/ngx_http_core_module.html#location 우리는 위치 블록에 대해 허용 된 컨텍스트가 서버 및 위치라는 것을 알게됩니다.

는 그래서 그래 당신은 서버 블록 내부에 위치 블록을 둘 필요가 (또는 다른 위치 블록 안에 중첩하지만 설정은 그렇게하지 않습니다)

gzip을 비트는 "HTTP 서버의 컨텍스트를 허용 한 위치, 위치에있는 경우 "http://nginx.org/en/docs/http/ngx_http_gzip_module.html#gzip에 따라, 그래서 당신은 http 또는 서버 블록에 넣을 수 있습니다.