Last active
August 3, 2017 19:55
-
-
Save takeshiyako2/5cd855e9d3bc2e55b8cb5d5f70d1ff6e to your computer and use it in GitHub Desktop.
WordPress + Varnish (Varnish port 80 -> nginx port 8080 -> php-fpm)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /etc/nginx/conf.d/default.conf | |
server { | |
listen 8080; | |
server_name localhost; | |
root /usr/share/nginx/wordpress; | |
index index.php; | |
location ~ \.php$ { | |
fastcgi_pass 127.0.0.1:9000; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
include fastcgi_params; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /etc/varnish/default.vcl | |
# This is an example VCL file for Varnish. | |
# | |
# It does not do anything by default, delegating control to the | |
# builtin VCL. The builtin VCL is called when there is no explicit | |
# return statement. | |
# | |
# See the VCL chapters in the Users Guide at https://www.varnish-cache.org/docs/ | |
# and https://www.varnish-cache.org/trac/wiki/VCLExamples for more examples. | |
# Marker to tell the VCL compiler that this VCL has been adapted to the | |
# new 4.0 format. | |
vcl 4.0; | |
# Default backend definition. Set this to point to your content server. | |
backend default { | |
.host = "127.0.0.1"; | |
.port = "8080"; | |
} | |
# Access control for BAN | |
acl purge { | |
"localhost"; | |
} | |
sub vcl_recv { | |
# Happens before we check if we have this in cache already. | |
# | |
# Typically you clean up the request here, removing cookies you don't need, | |
# rewriting the request, etc. | |
# BAN settings | |
if (req.method == "BAN") { | |
if (!client.ip ~ purge) { | |
return(synth(403, "Not allowed.")); | |
} | |
ban("req.url ~ /"); | |
return(synth(200, "Ban added")); | |
} | |
# Enable cookies & no cache for WordPress admin page | |
if( req.url ~ "^/wp-(login|admin)" || req.http.Cookie ~ "wordpress_logged_in_" ){ | |
return (pass); | |
} | |
# Ignore cookies for contents | |
unset req.http.Cookie; | |
# Return Cache | |
return (hash); | |
} | |
sub vcl_backend_response { | |
# Happens after we have read the response headers from the backend. | |
# | |
# Here you clean the response headers, removing silly Set-Cookie headers | |
# and other mistakes your backend does. | |
} | |
sub vcl_deliver { | |
# Happens when we have all the pieces we need, and are about to send the | |
# response to the client. | |
# | |
# You can do accounting or modifying the final object here. | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /etc/sysconfig/varnish | |
# Configuration file for Varnish Cache | |
# | |
# /etc/init.d/varnish expects the variable $DAEMON_OPTS to be set from this | |
# shell script fragment. | |
# | |
# Maximum number of open files (for ulimit -n) | |
NFILES=131072 | |
# Locked shared memory (for ulimit -l) | |
# Default log size is 82MB + header | |
MEMLOCK=82000 | |
# Maximum number of threads (for ulimit -u) | |
NPROCS="unlimited" | |
# Maximum size of corefile (for ulimit -c). Default in Fedora is 0 | |
# DAEMON_COREFILE_LIMIT="unlimited" | |
# Init script support to reload/switch vcl without restart. | |
# To make this work, you need to set the following variables | |
# explicit: VARNISH_VCL_CONF, VARNISH_ADMIN_LISTEN_ADDRESS, | |
# VARNISH_ADMIN_LISTEN_PORT, VARNISH_SECRET_FILE. | |
RELOAD_VCL=1 | |
# Main configuration file. | |
VARNISH_VCL_CONF=/etc/varnish/default.vcl | |
# | |
# Default address and port to bind to | |
# Blank address means all IPv4 and IPv6 interfaces, otherwise specify | |
# a host name, an IPv4 dotted quad, or an IPv6 address in brackets. | |
#VARNISH_LISTEN_PORT=6081 | |
VARNISH_LISTEN_PORT=80 | |
# | |
# Telnet admin interface listen address and port | |
VARNISH_ADMIN_LISTEN_ADDRESS=127.0.0.1 | |
VARNISH_ADMIN_LISTEN_PORT=6082 | |
# | |
# Shared secret file for admin interface | |
VARNISH_SECRET_FILE=/etc/varnish/secret | |
# | |
# The minimum number of worker threads to start | |
VARNISH_MIN_THREADS=50 | |
# | |
# The Maximum number of worker threads to start | |
VARNISH_MAX_THREADS=1000 | |
# | |
# Cache file size: in bytes, optionally using k / M / G / T suffix. | |
VARNISH_STORAGE_SIZE=256M | |
# | |
# Backend storage specification | |
VARNISH_STORAGE="malloc,${VARNISH_STORAGE_SIZE}" | |
# | |
# Default TTL used when the backend does not specify one | |
VARNISH_TTL=120 | |
# | |
# DAEMON_OPTS is used by the init script. | |
DAEMON_OPTS="-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} \ | |
-f ${VARNISH_VCL_CONF} \ | |
-T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} \ | |
-p thread_pool_min=${VARNISH_MIN_THREADS} \ | |
-p thread_pool_max=${VARNISH_MAX_THREADS} \ | |
-S ${VARNISH_SECRET_FILE} \ | |
-s ${VARNISH_STORAGE}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment