微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – Nginx:使用fastcgi_pass时覆盖主机头

我正在尝试覆盖使用fastcgi_pass时传递给基于PHP的应用程序(特别是Phabricator)的http主机头.
我在使用proxy_pass时发现了很多这样做的例子,但我似乎无法找到如何使用fastcgi_pass执行此操作的示例.具体来说,我希望代理的PHP应用程序将主机头看作“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;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐