10月27日 实现lnamp 动静分离,加缓存

10月27日 实现lnamp 动静分离,加缓存_第1张图片
无标题1.png
1、在a上的设置
yum install nginx
nginx    ---启动服务
vim /etc/nginx/nginx.conf
  proxy_cache_path /var/lib/nginx/tmp/pcache levels=1:1:2 keys_zone=proxycache:20m inactive=120s max_size=1g;
 fastcgi_cache_path /var/lib/nginx/tmp/fastcgicache levels=1:2:2 keys_zone=fastcgicache:20m inactive=120s max_size=1g;
        upstream webserver {    
                server 172.18.21.106:80 weight=2;
                server 172.18.21.7:80;
        }
vim /etc/nginx/conf.d/vhost.conf 
server{
        listen 80 default_server;
        server_name www.a.com;
        root /app/website1;
        location  ~* \.(html|jpg)$ {
        proxy_pass http://webserver;
        proxy_cache proxycache;
        proxy_cache_key $request_uri;
        proxy_cache_valid 200 301 302 1h;
        proxy_cache_valid any 1m;

}
        location ~* \.php$ {
                fastcgi_pass 172.18.21.6:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME /app/php$fastcgi_script_name;
               include fastcgi_params;
               fastcgi_cache fastcgicache;
               fastcgi_cache_key $request_uri;
               fastcgi_cache_valid 200 301 302 1h;
               fastcgi_cache_valid any 1m;
}
}
nginx -t
nginx -s reload
2、在两台apache服务器上的设置
yum install httpd
cd /var/www/html
vim index.html   ---制作好网页的页面
systemctl start httpd
systemctl enable httpd
3、在d上的设置
yum install php-fpm php-mysql
vim /etc/php-fpm.d/www.conf 
listen = 9000
;listen.allowed_clients = 127.0.0.1  ---将这一行用分号注释掉,默认是允许任何人访问
service php-fpm start
chkconfg php-fpm on
mkdir /app/php   ---创建存放php程序的主目录
cd /app/php
vim test.php

4、在e上的设置
yum install mysql-server
service mysqld start
chkconfig mysqld on
mysql
mysql> create database wpdb;
mysql> grant all on wpdb.* to [email protected] indentified by "centos";
mysql> quit
5、在浏览器上测试
http://www.a.com/index.html   ---因为有缓存,所有总是访问的同一个realserver,把缓存关闭就可以看到轮询模式了
http://www.a.com/test.php  ---看到连接数据库成功

你可能感兴趣的:(10月27日 实现lnamp 动静分离,加缓存)