Skip to content

CHICPRO

  • Life Log
  • Cycling Log
  • Photo Log
    • Portrait
    • Landscape
    • Flower
    • Etc
  • Coding Log
  • Information

WP Super Cache 사용을 위한 Nginx rewrite 설정

2013-12-14 by 편리

아침밥을 먹고 멍하니 있다가 서버로 뭔가 할 게 없나 생각 중에 cache 설정을 해야겠다는 생각이 들어서 WP Super Cache 플러그인을 설치하고 Nginx에 설정을 추가했다. 구글링해서 설정을 추가하긴 했는데 제대로 작동이 되는지는 잘 모르겠다. cache 파일이 생성은 되는데 rewrite 규칙이 잘 적용이 되고 있는지는 모르겠다. 이런 건 어떻게 확인을 해봐야할런지.. ㅎㅎ

    server {
        client_max_body_size 20M;
	listen       80;
        server_name  ncube.net www.ncube.net;
	server_tokens off;

        #charset koi8-r;

        #access_log  logs/chicpro.dev.access.log  main;

        root /home/ncube/www;
        index index.php index.html;

        set $cache_uri $request_uri;

        # POST requests and urls with a query string should always go to PHP
        if ($request_method = POST) {
            set $cache_uri 'null cache';
        }   
        if ($query_string != "") {
            set $cache_uri 'null cache';
        }   

        # Don't cache uris containing the following segments
        if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
            set $cache_uri 'null cache';
        }   

        # Don't use the cache for logged in users or recent commenters
        if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") {
            set $cache_uri 'null cache';
        }

        location / {
	    #try_files $uri $uri/ /index.php?$args;
	    try_files /wp-content/cache/supercache/$http_host/$cache_uri/index.html $uri $uri/ /index.php;
        }

        location = /favicon.ico { log_not_found off; access_log off; }
        location = /robots.txt  { log_not_found off; access_log off; }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        #error_page   500 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$ {
	    try_files $uri /index.php;
            fastcgi_index  index.php;
            include        fastcgi_params;
	    fastcgi_pass   unix:/var/run/php-fpm.ncube.net.sock;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
            deny  all;
        }

        location ~* \.(jpg|png|gif|js|css)$ {
            valid_referers none blocked ncube.net www.ncube.net;
            if ($invalid_referer) {
                return 444;
            }
        }

        # Cache static files for as long as possible
        location ~* .(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
            expires max;
            log_not_found off;
            access_log off;
        }
    }

출처 : https://rtcamp.com/wordpress-nginx/tutorials/single-site/wp-super-cache/

WP Super Cache를 위한 설정 외에 이것저것 추가한 설정이다. 이미지 외부링크 금지와 expire 설정도 추가되어 있다. Apache를 사용하면 자동으로 mod_rewrite 설정이 추가되지만 nginx에서는 이렇게 직접 추가를 해줘야 한다. 아파치만큼 자료가 많치 않아서 처음 사용하게 되면 힘들기도 하지만 이제는 점점 더 익숙해 가는 것 같다. 좀 더 익숙해지고 많이 알아가고 싶지만 개발일과 동시에 하기에는 쉽지만은 않언 것 같다.

Post navigation

Previous Post:

PHP 5.5.7 업데이트

Next Post:

넥서스5 월요일엔 받을 수 있겠다

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • php 배열 연산에서 + 와 array_merge 의 차이
  • pcntl_fork 를 이용한 다중 프로세스 실행
  • 아이폰 단축어를 이용하여 주중 공휴일엔 알람 울리지 않게 하기
  • 구글 캘린더 전체일정 재동기화
  • OpenLiteSpeed 웹서버에 HTTP 인증 적용
  • OpenLiteSpeed 웹어드민 도메인 연결
  • WireGuard를 이용한 VPN 환경 구축
  • Ubuntu 22.04 서버에 OpenLiteSpeed 웹서버 세팅
  • 맥 vim 세팅
  • 우분투 시스템 터미널쉘 zsh 로 변경

Recent Comments

  • 편리 on 업무관리용 그누보드 게시판 스킨
  • 임종섭 on 업무관리용 그누보드 게시판 스킨
  • 캐논 5D 펌웨어 | Dslr 펌웨어 업그레이드 방법 82 개의 베스트 답변 on 캐논 EOS 30D 펌웨어 Ver 1.0.6 , EOS 5D 펌웨어 Ver 1.1.1
  • Top 5 캐논 5D 펌웨어 Top 89 Best Answers on 캐논 EOS 30D 펌웨어 Ver 1.0.6 , EOS 5D 펌웨어 Ver 1.1.1
  • 편리 on 워드프레스 애니메이션 gif 파일을 mp4로 변환하여 출력하기
  • 임팀장 on 워드프레스 애니메이션 gif 파일을 mp4로 변환하여 출력하기
  • 편리 on Notepad++ NppFTP 플러그인 수동 설치
  • paul-j on Notepad++ NppFTP 플러그인 수동 설치
  • YS on Windows 10 iCloud 사진 저장 폴더 변경
  • 편리 on Docker를 이용한 Centos7 + httpd + php 5.4 개발환경 구축

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
© 2025 CHICPRO | Built using WordPress and SuperbThemes