Centos构建Apache Nginx负载平衡 动静分离实践总结


Centos7.x安装nginx

rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum install -y nginx
sudo systemctl start nginx.service
sudo systemctl enable nginx.service

Centos6.8安装nginx

使用yum安装nginx,安装nginx库
rpm -Uvh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
yum -y install nginx
service nginx start

安装Apache

yum install httpd* php php-mysql -y
vi /etc/httpd/config/httpd.conf 监听端口修改为非80端口 因为Nginx冲突
分别启动
service httpd start
service nginx start

实现动静分离 修改配置文件

vi /etc/nginx/conf.d/default.conf

upstream httpd {
server 10.0.0.5:88 weight=1 max_fails=1 fail_timeout=30s;
#server 10.0.0.4:88 weight=1 max_fails=1 fail_timeout=30s;
}
server {
listen 80;
server_name www.xiaohong.com;
root /var/www/html;
index index.html index.htm;
location /
{
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://httpd;
expires 3d;
}
location ~ .*\.(php|jsp|cgi)?$
{
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://httpd;
}
#配置Nginx动静分离,定义的静态页面直接从Nginx发布目录读取。
location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$
{
root /var/www/html;
expires 3d;
}

最后把各种服务设为开机启动
chkconfig httpd on
chkconfig nginx on

声明:ITMO|版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - Centos构建Apache Nginx负载平衡 动静分离实践总结


欢迎访问我的博客 -- IT猫