2
  • The links get broken right after I create them.
  • I use ln correctly. ln -s SOURCE TARGET

Create symbolic link

$ sudo ln -s ./sites-available/examble.domain.com ./sites-enabled

Compile NGINX - fails due to broken symbolic links

Note: The problem is not related to NGINX, NGINX compilation was just there to help me realize that the problem exists. The solution described below applies to any other related problem.

$ sudo nginx -t
nginx: [emerg] open() "/etc/nginx/sites-enabled/example.domain.com" failed (2: No such file or directory) in /etc/nginx/nginx.conf:62
nginx: configuration file /etc/nginx/nginx.conf test failed

Confirm that the symbolic links are broken

$ file ./sites-enabled/example.domain.com
./sites-enabled/example.domain.com: broken symbolic link to ./sites-available/example.domain.com
Eksapsy
  • 1,541
  • 3
  • 18
  • 26
  • Here's your duplicate... [How to symlink a file in Linux?](https://stackoverflow.com/q/1951742/608639) – jww Oct 05 '18 at 01:58
  • @jww No it's not. That answer would have confused me and wouldn't provide me any answers on why mine does not work. I fully describe why this doesn't work, saying that you're supposed to include the source like you're in the destination folder, which the Answer OR the Question of the proposed "Duplicate" question does not contain. Be fully aware, that I wrote this answer to help people like me, who struggled for hours with this. **IMPORTANT NOTE** The answer of the "duplicate" **does not contain RELATIVE paths**. Only ABSOLUTE ones. – Eksapsy Oct 08 '18 at 11:00

1 Answers1

9

The problem is that SOURCE is not re-interpreted when placed to the target directory.

So, if your file that you want to link is ~/file and you want to link it to ~/folder using:

ln -s ./file ./folder/

Then the symbolic link will think that file is at ~/folder/file instead of ~/file

So, instead, you have to get into the directory ~/folder and execute the ln command from there.

So, Problem is ...

ln needs the relative SOURCE directory to TARGET directory. Not the relative SOURCE directory to your current one.

Final Solution

# Getting into the folder
cd ./sites-enabled

# Creating symbolic link
ln -s ../sites-available/example.domain.com ./
Eksapsy
  • 1,541
  • 3
  • 18
  • 26
  • 2
    Of course you could also use `ln -s ../sites-available/example.domain.com sites-enabled`, without `cd`. The clever part about this solution is that if you *do* `cd` to the dir first, you can use any tab completable path because it'll already be relative to the correct directory. – that other guy Sep 27 '18 at 16:06
  • Correct, it avoids confusion and helps tabbing. In fact, I wasn't sure if this would work outside the `TARGET` path. Thanks for your contribution and help! – Eksapsy Sep 27 '18 at 16:42