G
G
gudron2013-12-24 00:50:48
PHP
gudron, 2013-12-24 00:50:48

nginx + php-fpm + chroot + symlink = brokenlink?

Good day.
The environment is generally standard:
Ubuntu with nginx on board. Which works with php-fpm which in turn is locked in its own cage and works through the chroot parameter, each host from its own user.
Chroot-path:
/home/www/vhostdata/example.dev/
The project itself is in
/home/www/vhostdata/example.dev/home/htdocks/
but for a chrooted user, this path looks like -
/home/htdocks/
Hence the problem.
In my case it is yii framework. Assets Manager creates symlinks based on the chroot.
That is - nginx goes to /home/www/vhostdata/example.dev/home/htdocks/web/assets and sees the following there:

lrwxrwxrwx 1 example.dev example.dev   39 дек.  24 00:37 509ca038 -> /home/htdocks/web/themes/default/assets
lrwxrwxrwx 1 example.dev example.dev   64 дек.  24 00:37 5d465bfb -> /home/htdocks/web/protected/vendors/framework/zii/widgets/assets
lrwxrwxrwx 1 example.dev example.dev   55 дек.  24 00:37 7b30adf2 -> /home/htdocks/web/protected/extensions/bootstrap/assets
lrwxrwxrwx 1 example.dev example.dev   59 дек.  24 00:37 a0ef63b0 -> /home/htdocks/web/protected/vendors/framework/web/js/source
lrwxrwxrwx 1 example.dev example.dev   56 дек.  24 00:37 f5a86c4c -> /home/htdocks/web/protected/extensions/highcharts/assets

And naturally he perceives this case as a broken link, because nginx itself works outside the chrooted environment and for it these links really refer to nowhere.
Who met with this problem? How did they decide?
ln -s ../web/assets 7b30adf2
It seems to me not right to make symlinks to relative addresses in php , and to rewrite the framework library for this. And there are a lot of them (frameworks), you can’t rewrite each one.
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
R
Ramzeska, 2013-12-24
@Ramzeska

Try using hardlinks.

ln ЦЕЛЬ ИМЯ_ССЫЛКИ
По умолчанию создаются жёсткие ссылки

G
gudron, 2013-12-24
@gudron

from mana ubunta on ln

-d, -F, --directory
allow the superuser to attempt to hard link directories (note: will probably fail due to system restrictions, even for the superuser)

 That is, by default, you cannot create a hardlink to a directory. And if possible, then only to the super user, and only on Linux. On MacOSX, ln does not have such a parameter. On freebsd, it is also possible, there is nothing to check at the moment.
Plus, you need to change the behavior of the yii framework, or any other framework, which is not good.
In general - an option, but rather conditional. I would like a more general solution.

A
Alexey Sundukov, 2013-12-24
@alekciy

And from what it follows that the problem is in Yii? I have a whole bunch of Yii installations running in chroots and everything works without problems. But Yii 1.1.14 does not create a symlink in assets.

G
gudron, 2013-12-24
@gudron

the problem is not in yii. and I already mentioned it 2 times.
Specifically, you may not have set the option in yii protected/config/main.php

'assetManager' => array(
      'class'         => 'CAssetManager',
      'linkAssets'    => true
),

The problem is general. Symlinks are created relative to the chroot path. and outside the chroot, these symlinks refer to the void.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question