LoginSignup
0
1

More than 5 years have passed since last update.

eccube4を下層ディレクトリへリバースプロキシ

Posted at

はじめに

表題の件での対応メモです。
リバースプロキシの設定は初めてだったので、ちょっとハマりました。

やりたいこと

(1)webサイト(wordpress) : https://hoge.com
(2)ecサイト(eccube4) : https://shop.hoge.com

リバースプロキシで別サーバにあるecサイトを本家サイトのサブフォルダ配下にあるように見せたい。
https://hoge.com/shop -> reserve proxy - > https://shop.hoge.com

設定(1) - webサイト側

confに以下を設定。.htaccessでは設定できないので注意。

vhosts.conf
SSLProxyEngine On
ProxyPass /shop https://shop.hoge.com
ProxyPassReverse /shop https://shop.hoge.com

問題点

css/js/imageなどが読み込めない!
eccube4では、url生成にsymfony/twigの以下の関数を利用しています。

(1)asset('style.css')
=> /html/template/default/style.css => https://hoge.com/html/template/default/style.css => エラー
↓本当はこうしたい
https://hoge.com/shop/html/template/default/style.css

(2)url('homepage')
=> https://shop.hoge.com/ => エラーではないが、このドメインは見せたくない
↓本当はこうしたい
https://hoge.com/shop

上記関数のソースを直すことはやりたくないし、symfonyの設定等で変更できそうな気がするが、ググってもわからず。
ちょっと力業になるが、以下のように対応した。

設定(1)・改 - webサイト側

vhosts.conf
SSLProxyEngine On
ProxyPass /shop https://shop.hoge.com/shop
ProxyPassReverse /shop https://shop.hoge.com/shop

設定(2) - ecサイト側

(1)サブフォルダ(shop)配下で動作するように構成を変更。これによってasset()の問題を回避
(2)HTTP_HOSTの書き換え。これによってurl()の問題を回避

index.php
$_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST'];

ただし、Requestクラスを生成する前に実行する必要あり。

最後に

もっとスマートな対応方法があれば教えてください。

0
1
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
0
1