Nginx:使用fastcgi_pass时覆盖主机头 [英] Nginx: Override host header when using fastcgi_pass

查看:147
本文介绍了Nginx:使用fastcgi_pass时覆盖主机头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to override the http host header that is passed to my php-based application (specifically Phabricator) when using fastcgi_pass.
I've found a lot of examples for doing this when using proxy_pass, but I can't seem to find an example of how to do this with fastcgi_pass. Specifically, I'd like the proxied php application to see the host header as "phabricator.localhost".

(这样做的原因是我想将多个不同的域与Phabricator Webapp关联,但是它只允许关联一个域,并且它拒绝所有未请求使用该域的请求.)

(The reason for this is that I want to associate several different domains with the Phabricator webapp, but it only allows one domain to be associated and it rejects any requests not made that that one domain.)

我对使用FastCGI配置Nginx很陌生,所以我不确定fastcgi的工作方式.感谢您的帮助.

I'm pretty new to configuring Nginx with FastCGI, so I'm not sure how fastcgi works. Any help is appreciated.

这是我的Nginx服务器配置:

Here is my Nginx server configuration:

  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?以下对我有用:

Have you tried HTTP_HOST? The following works for me:

fastcgi_param HTTP_HOST phabricator.localhost;

这篇关于Nginx:使用fastcgi_pass时覆盖主机头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆