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

前端之家收集整理的这篇文章主要介绍了php – Nginx:使用fastcgi_pass时覆盖主机头前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

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

我很擅长用FastCGI配置Nginx,所以我不确定fastcgi的工作原理.任何帮助表示赞赏.

这是我的Nginx服务器配置:

  1. server {
  2. server_name phabricator.localhost www.example.com example.com;
  3. root /opt/phabricator/phabricator/webroot;
  4. location / {
  5. index index.PHP;
  6. rewrite ^/(.*)$/index.PHP?__path__=/$1 last;
  7. }
  8. location = /favicon.ico {
  9. try_files $uri =204;
  10. }
  11. location /index.PHP {
  12. fastcgi_pass localhost:9000;
  13. fastcgi_index index.PHP;
  14. #### HERE ARE MY ATTEMPTS #####
  15. #proxy_set_header HOST phabricator.localhost;
  16. #fastcgi_param SERVER_NAME phabricator.localhost;
  17. #fastcgi_pass_header 'Host: phabricator.localhost';
  18. #fastcgi_pass_header 'Host: phabricator.localhost';
  19. #add_header Host phabricator.localhost;
  20. #proxy_set_header Host phabricator.localhost;
  21. #### END ATTEMPTS ####
  22. fastcgi_param REDIRECT_STATUS 200;
  23. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  24. fastcgi_param QUERY_STRING $query_string;
  25. fastcgi_param REQUEST_METHOD $request_method;
  26. fastcgi_param CONTENT_TYPE $content_type;
  27. fastcgi_param CONTENT_LENGTH $content_length;
  28. fastcgi_param SCRIPT_NAME $fastcgi_script_name;
  29. fastcgi_param GATEWAY_INTERFACE CGI/1.1;
  30. fastcgi_param SERVER_SOFTWARE Nginx/$Nginx_version;
  31. fastcgi_param REMOTE_ADDR $remote_addr;
  32. }
  33. }
最佳答案
你试过HTTP_HOST吗?以下为我工作:

  1. fastcgi_param HTTP_HOST phabricator.localhost;

猜你在找的Nginx相关文章