nginx+uwsgi 配置处理大流量

nginx+uwsgi configuration to handle heavy traffic

我正在尝试在 nginx+uWSGI 服务器上托管我的 django 应用程序。这是我的 nginx 配置

user www-data;
worker_processes 6;
pid /run/nginx.pid;

events {

            worker_connections 1024;
            multi_accept on;
    }

    http {

            sendfile on;
            tcp_nopush on;
            tcp_nodelay on;
            keepalive_timeout 65;
            types_hash_max_size 2048;

            include /etc/nginx/mime.types;
            default_type application/octet-stream;

            access_log /var/log/nginx/access.log;
            error_log /var/log/nginx/error.log;

            gzip on;
            gzip_disable "msie6";

            include /etc/nginx/conf.d/*.conf;
            include /etc/nginx/sites-enabled/*;
    }

我正在使用 uWSGI 作为中间件。这是启动服务器的 uWSGI 命令

        uwsgi --chdir=/path/to/your/project \
        --module=mysite.wsgi:application \
        --env DJANGO_SETTINGS_MODULE=mysite.settings \
        --master --pidfile=/tmp/project-master.pid \
        --socket=127.0.0.1:49152 \      
        --processes=5 \                 
        --uid=1000 --gid=2000 \        
        --harakiri=20 \                 
        --max-requests=5000 \          
        --vacuum \                      
        --home=/path/to/virtual/env \   
        --daemonize=/var/log/uwsgi/yourproject.log     

我有几个与此相关的问题。

  1. 我应该如何为 uWSGI 配置定义进程的值?

  2. 重新生成特定进程的主要目的是什么?

  3. --vacuum 将如何帮助加速服务器?

  4. 如前所述,我预计此服务器上的流量很大,因此是否需要任何其他自定义设置?

  1. 正如您在 docs
  2. 中看到的那样

You need to experiment with various setups and be prepared to constantly monitor your apps. uwsgitop could be a great tool to find the best values.

  1. 见 1.
  2. Vacuum 不会加速您的服务器,它只是在退出时清理环境(例如,如果您将使用 unix 套接字而不是 http,清理它是一个好习惯)
  3. Link 在第一个答案中 - 首先是 'must have',对于其他建议,我们需要更多信息。