Nginx

錯誤:nginx 重新啟動時“uwsgi_param”指令中的參數數量無效

  • July 8, 2015

CentOS 6.6,nginx 1.0.15。

我正在嘗試使用本教程配置 nginx <-> uwsgi <-> Django 堆棧。nginx 配置文件是:

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 行混淆了,這是一個 HTTPS 配置(假設第 1 行為空白)。

我該如何解決?

nginx 抱怨這一行:

uwsgi_param  HTTPS              $https if_not_empty;

if_not_empty參數是在nginx 1.1.11 中添加的,所以你的nginx 版本太舊,無法使用。

由於您在 CentOS 上,因此您應該執行nginx.org 自己的 CentOS 儲存庫提供的最新穩定 nginx 。通過這種方法更新到最新的穩定版 nginx 即可解決問題。

引用自:https://serverfault.com/questions/704366