红联Linux门户
Linux帮助

Nginx+Varnish缓存+WordPress+Ubuntu

发布时间:2016-08-24 15:45:57来源:topspeedsnail.com作者:斗大的熊猫
为了提高WordPress的响应速度,可以使用Varnish-HTTP加速器。Varnish主要做缓存和反向代理,提速非常明显。
 
Ubuntu安装Wordpress(Nginx+Varnish):
 
1.安装配置LEMP
$ sudo apt-get install nginx mysql-server php php-fpm php-mysql php-gd php-xml
在弹出窗口设置MySQL root密码。
配置Nginx:
$ sudo vim /etc/nginx/sites-available/default
写入如下内容:
server {
listen 127.0.0.1:8080 default_server;
listen [::]:8080 default_server;
root /var/www/html/wordpress;
index index.php index.html index.htm;
server_name yourdomain.com www.yourdomain.com;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
}
}
注意替换上面的域名。
重启Nginx:
$ sudo systemctl restart nginx
 
2.安装配置Varnish
$ sudo apt-get install varnish
编辑varnish配置文件:
$ sudo vim /etc/default/varnish
配置DAEMON_OPTS选项,把-a :6081改为80:
DAEMON_OPTS="-a :80 \
-T localhost:6082 \
-f /etc/varnish/default.vcl \
-S /etc/varnish/secret \
-s malloc,256m"
Nginx+Varnish缓存+WordPress+Ubuntu
同样需要更改如下文件:
$ sudo vim /lib/systemd/system/varnish.service
找到如下一行:
ExecStart=/usr/sbin/varnishd -j unix,user=vcache -F -a :6081 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m
把6081改为80:
ExecStart=/usr/sbin/varnishd -j unix,user=vcache -F -a :80 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m
重启Nginx和varnish服务:
$ sudo systemctl daemon-reload
$ sudo systemctl restart varnish
$ sudo systemctl restart nginx
 
3.下载Wordpress
下载Wordpress:
$ wget http://wordpress.org/latest.tar.gz
解压到网站目录:
$ sudo tar -xvf latest.tar.gz -C /var/www/html/
更改目录权限:
$ sudo chmod -R 755 /var/www/html/wordpress
$ sudo chown -R www-data:www-data /var/www/html/wordpress
 
4.为Wordpress创建数据库
$ mysql -u root -p
mysql> CREATE DATABASE wordpress;
mysql> CREATE USER wpuser@localhost IDENTIFIED BY 'test1234';
mysql> GRANT ALL PRIVILEGES ON wordpress.* TO wpuser@localhost;
mysql> FLUSH PRIVILEGES;
mysql> \q
创建了wordpress数据库和一个用户wpuser,密码test1234。
 
5.完成安装
使用浏览器访问:http://yourdomain.com
Nginx+Varnish缓存+WordPress+Ubuntu
根据提示完成安装:
Nginx+Varnish缓存+WordPress+Ubuntu
 
本文永久更新地址:http://www.linuxdiyf.com/linux/23594.html