动静分离

2020-01-13  本文已影响0人  凤凤思密达萌萌哒

一、动静不分离 image.png

1、配置uwsgi
image.png 修改文件 image.png
2、启动应用程序的服务

nohup uwsgi qf-uwsgi.ini &

3、配置负载均衡器
vim /etc/nginx/conf.d/defaults.conf image.png
4、启动负载均衡器
1.yum安装的nginx
systemctl restart nginx
2.编译安装的nginx
/usr/local/nginx/sbin/nginx -s stop 
/usr/local/nginx/sbin/nginx
5、访问负载均衡的地址 image.png

二、动静分离

1、动静分类
image.png
2、拷贝静态资源到静态服务服务器的对应目录
image.png
3、配置静态服务器
[root@localhost web]# cat /etc/nginx/nginx.conf

user  nginx;
worker_processes  auto;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;
events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /var/log/nginx/access.log  main;
    sendfile        on;
    keepalive_timeout  65;
    include /etc/nginx/conf.d/*.conf;
}
[root@localhost ~]# cat /etc/nginx/conf.d/defaults.conf 

server {
    listen       80;
    server_name  localhost;
    # 请求的静态资源到本地的 /opt/ 目录下获取
    location ~ \.(png|css|jpg|js)$ {
        root /opt/;
    }
    # 其他请求转发到 172.17.0.3:9090 动态资源服务器
    location / {
           include uwsgi_params;
           uwsgi_pass 172.17.0.3:9090;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

重启Nginx服务

4、动态网站服务器 image.png

启动此网站程序
uwsgi qf-uwsgi

5、配置负载均衡器
[root@localhost ~]# cat /etc/nginx/nginx.conf

ser  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}
http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /var/log/nginx/access.log  main;
    sendfile        on;
    keepalive_timeout  65;

    include /etc/nginx/conf.d/*.conf;
}
[root@localhost ~]# cat /etc/nginx/conf.d/default.conf 
upstream myweb {
    server 10.3.134.155;
}
server {
    listen       80;
    server_name  localhost;

    location / {
    proxy_pass http://myweb;
    }
}

启动负载均衡服务

1.yum安装重启方式
systemctl restart nginx
2.编译安装重启方式
/usr/local/nginx/sbin/nginx -s stop
/usr/local/nginx/sbin/nginx
上一篇 下一篇

猜你喜欢

热点阅读