首页 |  我的博客 |  查看该博主内容分类 | 

前后端分离项目nginx和uwsgi常用配置参考

1. nginx.conf

# 启动子进程默认用户
# #user  nobody;
# 一个主进程和多个工作进程。工作进程是单进程的,不需要特殊授权即可运行;这里定义的是工作进程数量
worker_processes  1;

# 全局错误日志的位置及日志格式
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    # 每个工作进程最大的并发数
    worker_connections  1024;
}


# http服务器设置
http {
    # 设定mime类型,类型由mime.type文件定义
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    # 此选项允许或禁止使用socket的TCP_CORK的选项,仅在使用sendfile的时候使用
    #tcp_nopush     on;

    # 长连接超时时间
    #keepalive_timeout  0;
    keepalive_timeout  65;

    # 开启压缩
    #gzip  on;

    # 配置虚拟主机
    server {
        # 虚拟主机使用的端口
        listen       80;
        # 虚拟主机域名
        server_name  xx.xx.xx.xx;
        # 虚拟主机支持的字符集,只对当前server生效
        charset utf-8;
        location / {
            # 根目录路径
            #root   html;
            # vue项目目录
            root /xxx/xxx/xxx/dist/;
            # 索引页
            index  index.html;
            # 解决刷新页面404问题
            try_files $uri $uri/ /index.html;
        }
        location /api {
            uwsgi_pass 0.0.0.0:port;
            include uwsgi_params;
        }
        error_page   500 502 503 504  /50x.html;

        # 定义页面路径
        location = /50x.html {
            root   html;
        }
    }
}

2. uwsgi.ini

[uwsgi]
# Django-related settings
# the base directory (full path)
# 填写项目的第一层绝对路径
chdir = /xx/xxx/xx项目文件夹
# Django's wsgi file
# 填写项目第二层的相对路径,找到第二层目录下的wsgi.py
module = 项目文件夹下xx文件夹.wsgi(一般为项目同名文件夹)
# 设置启用的配置文件,如果没有变更则不需要配置
# env = DJANGO_SETTINGS_MODULE=my_project.settings.pro
# the virtualenv (full path)
# 填写虚拟环境的第一层工作目录
home = /xxx/xxx/xxx/xxx环境文件夹(如:django)
# process-related settings
# master 主进程
master = true
# maximum number of worker processes
# 代表定义uwsgi运行的多进程数量,官网给出的优化建议是 2*cup核数+1
# 查看核数 cat /proc/cpuinfo| grep "cpu cores"| uniq
processes = 5
# the socket (use the full path to be safe)
socket = 0.0.0.0:port
# 临时使用http参数,便于用浏览器调试访问
# http = 0.0.0.0:port
# ... with appropriate permissions - may be needed
# chmod-socket = 664
# clear enviroment on exit
# 配置日志(记得创建logs文件夹,如果没有)
daemonize = %(chdir)/logs/uwsgi.log  # 会后台进行
# logto = %(chdir)/logs/uwsgi.log  # 不会后台进行
# 关闭uwsgi进程时自动清理socket文件
vacuum = true
buffer-size = 65535

nginx提高性能的配置[可选]

写在每个location / {...}中

proxy_set_header Host $host;  # 转发请求头信息
proxy_set_header X-Real-IP $remote_addr;  # 转发请求头信息
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  # 转发请求头信息
client_max_body_size 10m;  # 允许客户端请求的最大单文件字节数
client_body_buffer_size 128k;  # 缓冲区代理缓冲用户端请求的最大字节数
proxy_connect_timeout 90;  # nginx跟后端服务器连接超时时间(代理连接超时)
proxy_send_timeout 90;  # 后端服务器数据回传时间(代理发送超时)
proxy_read_timeout 90;  # 连接成功后,后端服务器响应时间(代理接收超时)
proxy_buffer_size 4k;  # 设置代理服务器保存用户头信息的缓冲区大小
proxy_buffers 4 32k;  # proxy_buffers缓冲区,网页平均在32k以下的话这样设置
proxy_busy_buffers_size 64k;  # 高负荷下缓冲大小(proxy_buffers*2)
proxy_temp_file_write_size 64k;  # 设定缓存文件夹大小,大于这个值,将从upstream服务器传
posted @ 2022-09-15 23:19  Z哎呀  阅读(432)  评论(0编辑  收藏  举报
// let homeEle = document.querySelector('body') // homeEle.setAttribute('id', 'particles-js') // /* ---- particles.js config ---- */ // particlesJS("particles-js", { // "particles": { // "number": { // "value": 380, // "density": { // "enable": true, // "value_area": 800 // } // }, // "color": { // "value": "#ffffff" // }, // "shape": { // "type": "circle", // "stroke": { // "width": 0, // "color": "#000000" // }, // "polygon": { // "nb_sides": 5 // }, // "image": { // "src": "img/github.svg", // "width": 100, // "height": 100 // } // }, // "opacity": { // "value": 0.5, // "random": false, // "anim": { // "enable": false, // "speed": 1, // "opacity_min": 0.1, // "sync": false // } // }, // "size": { // "value": 3, // "random": true, // "anim": { // "enable": false, // "speed": 40, // "size_min": 0.1, // "sync": false // } // }, // "line_linked": { // "enable": true, // "distance": 150, // "color": "#ffffff", // "opacity": 0.4, // "width": 1 // }, // "move": { // "enable": true, // "speed": 6, // "direction": "none", // "random": false, // "straight": false, // "out_mode": "out", // "bounce": false, // "attract": { // "enable": false, // "rotateX": 600, // "rotateY": 1200 // } // } // }, // "interactivity": { // "detect_on": "canvas", // "events": { // "onhover": { // "enable": true, // "mode": "grab" // }, // "onclick": { // "enable": true, // "mode": "push" // }, // "resize": true // }, // "modes": { // "grab": { // "distance": 140, // "line_linked": { // "opacity": 1 // } // }, // "bubble": { // "distance": 400, // "size": 40, // "duration": 2, // "opacity": 8, // "speed": 3 // }, // "repulse": { // "distance": 200, // "duration": 0.4 // }, // "push": { // "particles_nb": 4 // }, // "remove": { // "particles_nb": 2 // } // } // }, // "retina_detect": true // }); // var count_particles, stats, update; // stats = new Stats; // stats.setMode(0); // stats.domElement.style.position = 'absolute'; // stats.domElement.style.left = '0px'; // stats.domElement.style.top = '0px'; // document.body.appendChild(stats.domElement); // count_particles = document.querySelector('.js-count-particles'); // update = function() { // stats.begin(); // stats.end(); // if (window.pJSDom[0].pJS.particles && window.pJSDom[0].pJS.particles.array) { // count_particles.innerText = window.pJSDom[0].pJS.particles.array.length; // } // requestAnimationFrame(update); // }; // requestAnimationFrame(update);