nginx 重启时出现错误:“‘uwsgi_param’指令中的参数数量无效”

nginx 重启时出现错误:“‘uwsgi_param’指令中的参数数量无效”

CentOS 6.6,nginx 1.0.15。

我正在尝试配置 nginx <-> uwsgi <-> Django 堆栈,使用这个教程.nginx conf文件是:

upstream django {
    server 127.0.0.1:8001;
}

server {
    listen      8000;
    server_name 0.0.0.0; # an IP address of my server here
    charset     utf-8;
    client_max_body_size 75M;

    location /media  {
        alias /projects/myproject/media;
    }

    location /static {
        alias /projects/myproject/static;
    }

    location / {
        uwsgi_pass  django;
        include     /projects/myproject/uwsgi_params;
    }
}

uwsgi_params文件是:

uwsgi_param  QUERY_STRING       $query_string;
uwsgi_param  REQUEST_METHOD     $request_method;
uwsgi_param  CONTENT_TYPE       $content_type;
uwsgi_param  CONTENT_LENGTH     $content_length;

uwsgi_param  REQUEST_URI        $request_uri;
uwsgi_param  PATH_INFO          $document_uri;
uwsgi_param  DOCUMENT_ROOT      $document_root;
uwsgi_param  SERVER_PROTOCOL    $server_protocol;
uwsgi_param  REQUEST_SCHEME     $scheme;
uwsgi_param  HTTPS              $https if_not_empty;

uwsgi_param  REMOTE_ADDR        $remote_addr;
uwsgi_param  REMOTE_PORT        $remote_port;
uwsgi_param  SERVER_PORT        $server_port;
uwsgi_param  SERVER_NAME        $server_name;

当我尝试启动 nginx 时出现错误:

$ sudo service nginx restart
nginx: [emerg] invalid number of arguments in "uwsgi_param" directive in /projects/myproject/uwsgi_params:12
nginx: configuration file /etc/nginx/nginx.conf test failed

看起来 nginx 与 uwsgi_params 文件的第 12 行混淆了,该行(假设第 1 行为空白)是 HTTPS 配置。

我该如何修复它?

答案1

nginx 对这一行有抱怨:

uwsgi_param  HTTPS              $https if_not_empty;

if_not_empty参数是添加在nginx 1.1.11中,所以你的nginx版本太旧了,无法使用它。

由于你使用的是 CentOS,因此你应该运行由以下机构提供的最新稳定 nginx:nginx.org 自己的 CentOS 存储库通过此方法更新到最新的稳定nginx将解决该问题。

相关内容