【问题标题】:fastcgi_pass is calling but index.html is ignored in nginx.conffastcgi_pass 正在调用但 index.html 在 nginx.conf 中被忽略
【发布时间】:2014-05-04 13:02:43
【问题描述】:

我有以下业务逻辑: index.html 是从 root url (location /) 和 fastcgi 由 /fcgi url (location /fcgi) 调用,并且 我也将 url 参数发送到 fastcgi 并在那里解析。 在 nginx.conf 我有 2 个不同的位置:位置 / 和位置 /fcgi。 发生了什么:当我访问根 url localhost:9001/index.html 不是 从“location /”加载但调用“location /fcgi”并执行 fastcgi_pass 带有根网址。这打破了我的 fastcgi 程序,因为没有参数传递 它显示调试错误(在 Windows 上测试)。最后服务器显示页面错误 而不是简单地显示 index.html。为什么 root 匹配 localhost:9001/ 调用 "location /fcgi" 而不是 "location /" ?如何使 nginx 使用 url localhost:9001/ 加载 index.html 但不同时调用 /fcgi ?

Below is my nginx.conf.

server {
listen       9001;
server_name  localhost;
root   E:/data/;

location / { 
index  index.html;
}

location /fcgi {
fastcgi_pass 127.0.0.1:9002;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;
}

}

【问题讨论】:

  • 您提到端口 9000,但在您的配置服务器中监听 9001
  • 抱歉输入,已编辑为 9001,问题仍然存在
  • 我认为 nginx 没有理由这样做。你重启过nginx吗?你没有另一个服务器块在监听 9001 吗?
  • 每次更改 nginx.conf 后我都会重新启动。但是 location /fcgi 每次我只访问一个根 url 时都会调用。

标签: nginx fastcgi


【解决方案1】:

我发现这个问题的原因很简单: 在位置“/fcgi/”的末尾使用额外的斜杠而不是“/fcgi”。 在这种情况下,nginx 可以拆分调用,否则 nginx 会像处理一个位置一样处理位置“/”和“/fcgi”。如果有人能解释为什么它会这样工作,将不胜感激。

【讨论】:

    猜你喜欢
    • 2020-03-31
    • 2014-10-03
    • 2022-01-17
    • 1970-01-01
    • 1970-01-01
    • 2012-01-16
    • 2011-05-15
    • 2022-01-23
    • 1970-01-01
    相关资源
    最近更新 更多