AWS EC2 Ubuntu上搭建基于LNMP的WordPress
本文备忘搭建memleak.in的过程
平台:AWS EC2 Ubuntu Nginx MySQL Php Varnish WordPress
apt-get install nginx
service restart nginx
apt-get install php5-fpm
apt-get autoremove
cd /etc/nginx/sites-available
vi memleak.in
server {
listen 80;
server_name memleak.in;
root /var/www/memleak.in/public_html;
if ($http_host != “memleak.in”) {
rewrite ^ http://memleak.in$request_uri permanent;
}
index index.php index.html;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
rewrite ^/sitemap_index\.xml$ /index.php?sitemap=1 last;
rewrite ^/([^/]+?)-sitemap([0-9]+)?\.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
location ~* \.(jpg|jpeg|png|gif|css|js|ico)$ {
expires max;
log_not_found off;
}
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
ln -s /etc/nginx/sites-available/memleak.in /etc/nginx/sites-enabled/memleak.in
/etc/init.d/nginx reload
mkdir -p /var/www/memleak.in/public_html
chown -R www-data:www-data /var/www/memleak.in/public_html/
apt-get install php5-mysql
varnish
curl http://repo.varnish-cache.org/debian/GPG-key.txt | apt-key add –
echo “deb http://repo.varnish-cache.org/ubuntu/ trusty varnish-4.0″ >> /etc/apt/sources.list
apt-get update
apt-get install varnish
vi /etc/default/varnish
—————————
DAEMON_OPTS=”-a :80
—————————
vi /etc/varnish/default.vcl
—————————————————————-
backend default {
.host = “127.0.0.1”;
.port = “8080”;
}
# Drop any cookies sent to WordPress.
sub vcl_recv {
if (!(req.url ~ “wp-(login|admin)”)) {
unset req.http.cookie;
}
}
# Drop any cookies WordPress tries to send back to the client.
sub vcl_fetch {
if (!(req.url ~ “wp-(login|admin)”)) {
unset beresp.http.set-cookie;
}
}
—————————————————————-
swith to use varnish
vi /etc/nginx/sites-available/memleak.in
listen 8080;
/etc/init.d/nginx restart
/etc/init.d/varnish restart


