nginx动静分离

nginx动静分离

为了加快网站的解析速度,可以把动态页面和静态页面由不同的服务器来解析,加快解析速度。降低原来单个服务器的压力。 在动静分离的tomcat的时候比较明显,因为tomcat解析静态很慢,其实这些原理的话都很好理解,简单来说,就是使用正则表达式匹配过滤,然后交个不同的服务器。

192.168.187.142 代理服务器

192.168.187.172 动态资源

192.168.187.164 静态资源 (一般是指数据库资源。文字类型)

#地址池配置动静分离 
#vim /etc/nginx/conf.d/nginx.conf
[root@localhost conf.d]# cat upstream.conf 
upstream static {
        server 192.168.187.164  weight=1 max_fails=1 fail_timeout=60;
}
upstream  phpserver {
        server 192.168.187.172  weight=1 max_fails=1 fail_timeout=60;
}
server{
        listen 80;
        server_name  localhost;
        location ~\.(php|jps)$ {
        proxy_pass http://phpserver;
        proxy_set_header Host $host:$server_port;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
}
        location ~\.(htmlgif|jpg|png|bmp|swf|css|js)$ {
        proxy_pass http://static;
        proxy_set_header  Host $host:$server_port;
        proxy_set_header  X-Real-IP  $remote_addr;
        proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
}
}


192.168.187.164 静态资源

[root@localhost conf.d]# cat html.conf 
server {
	listen 80;
	server_name lolcahost;
	location ~\.(html|jpg|png|js|css|gif|bmp|jpeg) {
	root   /usr/share/nginx/html;
	index index.html;
	}
}

192.168.187.172 动态资源 (php)

1下载php
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum install php71w-xsl php71w php71w-ldap php71w-cli php71w-common php71w-devel php71w-gd php71w-pdo php71w-mysql php71w-mbstring php71w-bcmath php71w-mcrypt -y

yum install -y php71w-fpm
systemctl start php-fpm
2编辑nginx配置文件
[root@localhost conf.d]# cat php.conf 
server {
	listen 80;
	server_name localhost;
	location  ~\.php$ {
	root /usr/share/nginx/html;
	fastcgi_pass  192.168.187.172:9000;
	fastcgi_index index.php;
	fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
	include fastcgi_params;
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值