LoginSignup
5
5

More than 5 years have passed since last update.

Symfony2でx-forwarded-hostを優先する設定

Last updated at Posted at 2014-07-02

プロキシ経由でWebサーバにつなぐ構成の場合
デフォルトだとgenerateUrl()などで絶対URLにした時に、localのホスト名(http://web.*.local/xxx など)になってしまいます

例えば$this->redirect($this->generateUrl(xxx, xxx, true))のようにしていた場合、名前解決できずにエラーになるなど不都合です。

そこでx-forwarded-hostを優先する設定が必要になってきます

config.ymlに以下を設定


framework:
    trusted_proxies: [xxx.xxx.xxx.xxx] ←プロキシのIP

これで元々リクエストに来たドメインにてURLが作られます

参考:
なお、以前あった"trust_proxy_headers"は廃止されたようです
http://www.leaseweblabs.com/2013/06/symfony-2-3-lts-symfony2-with-long-term-support/

"trusted_proxies"の設定方法(公式)
http://symfony.com/doc/current/reference/configuration/framework.html#trusted-proxies

[Symfony 2.5.0]

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5