ECCUBE2,3をインストールする機会があったのでメモ。
例によってnginxの設定がめんどいですね。・・
ファイルパス
ECCUBE2,ECCUBE3ともに下記パス,URLと仮定します。
1 2 3 4 |
path /var/www/html/eccube/ url http://sample-ec.com/ |
Contents
nginxの設定
ECCUBE2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
location ~ / { root /var/www/html/eccube/html/; index index.html index.php; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_buffers 8 256k; fastcgi_buffer_size 256k; fastcgi_send_timeout 1800; fastcgi_read_timeout 1800; fastcgi_connect_timeout 1800; fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name; fastcgi_index index.php; include fastcgi_params; if ($request_uri ~* \.css$) { add_header Content-Type text/css; } access_log /var/log/nginx/eccube.access.log main; error_log /var/log/nginx/eccube.error.log notice; } |
上記の書き方はあまり見かけないタイプかも・・・おそらくはECCUBE3のような書き方に近い方法のほうが推奨だと思いますが、個人的に上記の設定で動いたのでメモしておきました。
php-fpm内でphp以外のファイルを動かす場合には、下記2点が必要です。
1 php-fpm内でphp以外のファイルをパースできるようにしておく
http://skill-up-engineering.com/?p=1416
(PHP以外のファイルを動かしたいときを参照。)
こちらひょっとすると非推奨かもしれないです(汗)。
2 mime-typeを適切に設定していないとtext/htmlで読み込みまれてしまいCSSが動きません。
(ブラウザのコンソールでエラーがでます)
ECCUBE3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
server { listen 80; server_name eccube3; #server_nameがeccube3の場合はドメイン以下は下記pathに飛びます root /var/www/html/eccube3/html/; rewrite_log on; location = /50x.html { root /usr/share/nginx/html; } #全ファイル共通のアクセスcsss.js.imgなどはここで処理されます location / { index index.php; try_files $uri $uri/ /index.php?u=$uri&$args; } location ~ \.php$ { try_files $uri =404; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_buffers 8 256k; fastcgi_buffer_size 256k; fastcgi_send_timeout 1800; fastcgi_read_timeout 1800; fastcgi_connect_timeout 1800; fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name; fastcgi_index index.php; include fastcgi_params; access_log /var/log/nginx/eccube3.access.log main; error_log /var/log/nginx/eccube3.error.log notice; } } |
ポイント
1 |
try_files $uri $uri/ /index.php?u=$uri&$args; |
ECCUBE2まではhtml直下のファイルパスとURLが対応していたので簡単だったんですが、ECCUBE3からはそうではないので、一工夫いります。
sameple-ec.com/index.phpだった場合にはいいんですが、sample-ec.com/product/listだった場合、ここにファイルパスがあるわけではありません。
本来の動くべきプログラムとURLが全然違う場所にあります。ECCUBE3の場合、index.phpですべて処理をし、URLをここに引き渡します。
要はindex.php?u=product/list.phpみたいな形で起動ポイントを引き渡す必要があります。そのためtry_filesの記述が必要になってきます。
実際に作業をするときはひたすらデバッグして、ログをみていろいろ実験してみましょう。
参考リンク