Nginx sites-enabled, sites-available: Cannot create soft-link between config files in Ubuntu 12.04

只愿长相守 提交于 2019-12-03 01:36:11

问题


I am trying to create soft links between config files containing server blocks in the sites-enabled and sites-available directories in /etc/nginx/.

The command I am using is:

sudo ln -s sites-available/foo.conf sites-enabled/

When I then execute:

ls -l

The result is:

lrwxrwxrwx 1 parallels parallels 27 Aug  6 20:44 immigrationinformation.conf -> immigrationinformation.conf

where the immigrationinformation.conf -> immigrationinformation.conf part has a charcoal with red typeface.

When I then try and access this soft-link, I am told that it is broken.

When I create the soft-link in the sites-available directory i.e.

sudo ln -s sites-available/foo.conf sites-available/foo_link.conf

it works as normal. However, if I then move this to the sites-enabled directory, the link is broken again.

I can create the soft link via the file manager GUI but not via the command line. I can also create hard-links with no problem.

I suspected it was a permissions issue so I have played around with setting all permissions to 777 of both directories and the directories themselves and also changing the owners to something other than root, but still with no luck.

Any help would me much appreciated, thank you.


回答1:


You need to start by understanding that the target of a symlink is a pathname. And it can be absolute or relative to the directory which contains the symlink

Assuming you have foo.conf in sites-available

Try

cd sites-enabled
sudo ln -s ../sites-available/foo.conf .
ls -l

Now you will have a symlink in sites-enabled called foo.conf which has a target ../sites-available/foo.conf

Just to be clear, the normal configuration for Apache is that the config files for potential sites live in sites-available and the symlinks for the enabled sites live in sites-enabled, pointing at targets in sites-available. That doesn't quite seem to be the case the way you describe your setup, but that is not your primary problem.

If you want a symlink to ALWAYS point at the same file, regardless of the where the symlink is located, then the target should be the full path.

ln -s /etc/apache2/sites-available/foo.conf mysimlink-whatever.conf

Here is (line 1 of) the output of my ls -l /etc/apache2/sites-enabled:

lrwxrwxrwx 1 root root  26 Jun 24 21:06 000-default -> ../sites-available/default

See how the target of the symlink is relative to the directory that contains the symlink (it starts with ".." meaning go up one directory).

Hardlinks are totally different because the target of a hardlink is not a directory entry but a filing system Inode.



来源:https://stackoverflow.com/questions/18089525/nginx-sites-enabled-sites-available-cannot-create-soft-link-between-config-fil

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!