美文网首页
动静分离

动静分离

作者: 凤凤思密达萌萌哒 | 来源:发表于2020-01-13 09:05 被阅读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

相关文章

  • 企业级你所要懂的实战应用,Nginx动静分离实战问题详解

    知识要点: Nginx动静分离简介 正则表达式回顾 Nginx动静分离配置 Nginx动静分离简介 动静分离是指在...

  • 动静分离

    1. 动静分离的实现思路 动静分离是将网站静态资源(HTML,JavaScript,CSS,img等文件)与后台应...

  • 动静分离

    1.什么是动静分离 将动态请求和静态请求区分访问 2.为什么要做动静分离 tomcat本身处理静态效率不高,还会带...

  • 动静分离

    一、动静不分离image.png 1、配置uwsgi image.png修改文件image.png 2、启动应用程...

  • Day44-Nginx集群架构:Tomcat动静分离+Rewri

    本章课程内容tomcat动静分离: 1.什么是动静分离? 2.为什么要做动静分离? 3.如何实现动静分离? 4.单...

  • 第四十四天 动静分离

    第四十四天 动静分离 1.什么是动静分离? 将动态请求和静态请求区分访问 动静分离的优点:动静分离之后,即使动态服...

  • Nginx动静分离

    https://blog.csdn.net/zsj777/article/details/80241558

  • nginx 动静分离

    //静态资源location ~ ..(js|css|htm|html|gif|jpg|jpeg|png|bmp|...

  • nginx动静分离

    1、准备环境准备一个nginx代理 两个http 分别处理动态和静态。 静态资源配置 动态资源配置:

  • nginx动静分离

    准备三台服务器 分别是代理, 静态, 动态 yum装的nginx主配置文件:/etc/nginx/nginx....

网友评论

      本文标题:动静分离

      本文链接:https://www.haomeiwen.com/subject/lzkpactx.html