06_C74部署_Nginx 动静分离

nginx01:192.168.189.79
nginx02:192.168.189.80
nginx 安装配置参考前面文章

一、安装NFS (nginx01 02 都要操作)
yum install rpcbind nfs-utils -y
启动NFS:
systemctl start rpcbind
systemctl start nfs
systemctl enable rpcbind
systemctl enable nfs

二、nginx 01、 nginx02 上部署网站 (nginx01 02 都要操作)
web01上面,打包网站文件
cd /usr/local/nginx/html
tar zcvf /tmp/disx3.4.tar.gz ./*
scp -r /tmp/disx3.4.tar.gz root@192.168.189.79:/tmp/
scp -r /tmp/disx3.4.tar.gz root@192.168.189.80:/tmp/
++++++++++++++++++++++++++++++++++

cd /tmp
tar zxvf disx3.4.tar.gz -C /usr/local/nginx/html/
mount -t nfs 192.168.189.175:/drbdnfs/exports/dir1/discuz/attachment /usr/local/nginx/html/data/attachment

chmod +x /etc/rc.d/rc.local
echo " mount -t nfs 192.168.189.175:/drbdnfs/exports/dir1/discuz/attachment /usr/local/nginx/html/data/attachment" >>/etc/rc.local

cd /usr/local/nginx/html/data/cache

#将缓存文件里面的IP,替换成nginx01、02的IP

++++++++++++++ nginx01 +++++++++++++
ls |xargs sed -i 's/192.168.189.73/192.168.189.79/g'
echo "192.168.189.79" >/usr/local/nginx/html/index.php.ip
++++++++++++ nginx02 +++++++++++++++
ls |xargs sed -i 's/192.168.189.73/192.168.189.80/g'
echo "192.168.189.80" >/usr/local/nginx/html/index.php.ip
+++++++++++++++++++++++++++++++++++++++++++++++++

systemctl restart nginx

三、配置动静分离 (nginx01 nginx02 都要操作)

vim /usr/local/nginx/conf/nginx.conf
worker_processes 4;
worker_rlimit_nofile 10000; #更改worker进程的最大打开文件数限制.
events {
worker_connections 40960;
use epoll;
}

http {
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nodelay on;
tcp_nopush on;
server_tokens off; #隐藏版本号。
keepalive_timeout 60;
gzip on;
gzip_disable "msie6"; #设置成IE6或者更低版本禁用gzip功能。
gzip_proxied any;
gzip_min_length 1000; #设置对数据启用压缩的最少字节数。
gzip_comp_level 6;
upstream web {
server 192.168.189.73:80 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.189.74:80 weight=1 max_fails=2 fail_timeout=30s;
}

server {
listen 80;
server_name localhost;
location / {
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://web;
root html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

#动态页面走189.73 189.74
location ~ .*\.(php|jsp|cgi)?$ {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://web;
}
location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css|mp4|wmv|flv)?$
{
root html; #静态页面走本地服务器。
expires 3d;
}
}
}
保存退出,重启。
systemctl restart nginx