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.  
  5. location / {
  6. index index.PHP;
  7. rewrite ^/(.*)$/index.PHP?__path__=/$1 last;
  8. }
  9.  
  10. location = /favicon.ico {
  11. try_files $uri =204;
  12. }
  13.  
  14. location /index.PHP {
  15. fastcgi_pass localhost:9000;
  16. fastcgi_index index.PHP;
  17.  
  18. #### HERE ARE MY ATTEMPTS #####
  19. #proxy_set_header HOST phabricator.localhost;
  20. #fastcgi_param SERVER_NAME phabricator.localhost;
  21. #fastcgi_pass_header 'Host: phabricator.localhost';
  22. #fastcgi_pass_header 'Host: phabricator.localhost';
  23. #add_header Host phabricator.localhost;
  24. #proxy_set_header Host phabricator.localhost;
  25. #### END ATTEMPTS ####
  26.  
  27. fastcgi_param REDIRECT_STATUS 200;
  28. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  29. fastcgi_param QUERY_STRING $query_string;
  30. fastcgi_param REQUEST_METHOD $request_method;
  31. fastcgi_param CONTENT_TYPE $content_type;
  32. fastcgi_param CONTENT_LENGTH $content_length;
  33. fastcgi_param SCRIPT_NAME $fastcgi_script_name;
  34. fastcgi_param GATEWAY_INTERFACE CGI/1.1;
  35. fastcgi_param SERVER_SOFTWARE Nginx/$Nginx_version;
  36. fastcgi_param REMOTE_ADDR $remote_addr;
  37. }
  38. }
你试过HTTP_HOST吗?以下为我工作:
  1. fastcgi_param HTTP_HOST phabricator.localhost;

猜你在找的PHP相关文章