php - Nginx:使用 fastcgi_pass 时覆盖主机 header

标签 php nginx fastcgi phabricator hostheader

在使用 fastcgi_pass 时,我试图覆盖传递到我的基于 php 的应用程序的 http 主机 header (特别是 Phabricator)。
我已经找到了很多使用 proxy_pass 时执行此操作的示例,但我似乎找不到如何使用 fastcgi_pass 执行此操作的示例。具体来说,我希望代理的 php 应用程序将主机 header 视为“phabricator.localhost”。

(这样做的原因是我想将几个不同的域与 Phabricator webapp 相关联,但它只允许关联一个域并且它拒绝任何不是该域的请求。)

我对使用 FastCGI 配置 Nginx 还很陌生,所以我不确定 fastcgi 是如何工作的。感谢您的帮助。

这是我的 Nginx 服务器配置:

  server {
    server_name phabricator.localhost  www.example.com example.com;
    root /opt/phabricator/phabricator/webroot;

    location / {
      index index.php;
      rewrite ^/(.*)$ /index.php?__path__=/$1 last;
    }

    location = /favicon.ico {
      try_files $uri =204;
    }

    location /index.php {
    fastcgi_pass   localhost:9000;
    fastcgi_index   index.php;

    #### HERE ARE MY ATTEMPTS #####
    #proxy_set_header HOST phabricator.localhost;
    #fastcgi_param SERVER_NAME phabricator.localhost;
    #fastcgi_pass_header 'Host: phabricator.localhost';
    #fastcgi_pass_header 'Host: phabricator.localhost';
    #add_header Host phabricator.localhost;
    #proxy_set_header Host phabricator.localhost;
    #### END ATTEMPTS ####

    fastcgi_param  REDIRECT_STATUS    200;
    fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    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_NAME        $fastcgi_script_name;
    fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
    fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;
    fastcgi_param  REMOTE_ADDR        $remote_addr;
  }
}

最佳答案

您尝试过 HTTP_HOST 吗?以下对我有用:

fastcgi_param HTTP_HOST phabricator.localhost;

关于php - Nginx:使用 fastcgi_pass 时覆盖主机 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28889673/

相关文章:

php - libapache2-mod-fastcgi 安装过程中出错

php - 为什么查询成功后我会从 mysqli_result::free 收到 fatal error ?

php代码来匹配数据库中的列日期并显示客户数据

php - APCu TTL 不工作 php 7.0

nginx - 在浏览器中检测 HTTP2/SPDY 支持

windows - 用于 Windows 的 php-fpm?

php 中的 php 以包含 wordpress 自定义字段

nginx - 使用 NGINX 进行动态路由

php - Nginx - Rails 上的 Wordpress 博客加载带有 mime 类型文本/html 的样式和脚本

c++ - 在 FastCGI 和 Octave 中重新定义标准输出