133

After over 10 hours of research I have not figured out why this doesn't work! I am trying to move my localhost to my sites-enabled folder which is in /etc/nginx/sites-enabled/default.

It IS a symlink from the sites-available folder. When using the following configuration I get an "unable to connect" using localhost:8080 as my address

nginx.conf (/usr/local/nginx/conf/nginx.conf):

user  www-data;
worker_processes  2;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    include /etc/nginx/sites-enabled/*; 
}

sites-available (/etc/nginx/sites-available/default):

server {
  listen   8080;
  root /home/myusername/myown/customdirectory;
  index index.php index.html index.htm;
  server_name localhost;

    location / {
        try_files $uri $uri/ /index.html;
    }

    location /doc/ {
        alias /usr/share/doc/;
        autoindex on;
        allow 127.0.0.1;
        allow ::1;
        deny all;
    }


    error_page 404 /404.html;

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/www;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}

I can get this working if I put the relevant info from sites available to the nginx.conf, I just can't figure out why it doesn't work this way?

Thanks!

4

4 Answers 4

228

I had the same problem. It was because I had accidentally used a relative path with the symbolic link.

Are you sure you used full paths, e.g.:

ln -s /etc/nginx/sites-available/example.com.conf /etc/nginx/sites-enabled/example.com.conf
6
  • 4
    May be a problem with an incorrect path in the relative link more than it being a relative link at all. For example, if your link doesn't start with ../ to traverse up one directory, then enter sites-available. If you can cat the symlink and get output, Nginx should read it also as @Hannes said. Using an absolute path simply makes an incorrect path much more difficult to do.
    – Bryson
    Commented Jan 25, 2014 at 23:13
  • isn't there a command line tool for getting the absolute path of a file?
    – user9903
    Commented Jul 3, 2014 at 23:35
  • 3
    Wow! This is precisely why sites-enabled is evil!
    – cnst
    Commented Aug 27, 2017 at 21:30
  • mine also relative path didn't work, but followed this and it just worked fine with absolute paths, Thanks a lot! :D Commented Jul 20, 2018 at 17:52
  • On WSL (Windows Subsystem for Linux), full path is required. Thanks for the hint!
    – By-Jokese
    Commented Jun 11, 2019 at 16:04
80

Changing from:

include /etc/nginx/sites-enabled/*; 

to

include /etc/nginx/sites-enabled/*.*; 

fixed my issue

5
  • 2
    how did you figure this out? It worked for me, but this is not obvious
    – afarley
    Commented Nov 20, 2018 at 4:58
  • 2
    That was the issue for me! But in my case, it was looking for *.conf and mine had a different ending. Crazy I wasted hours over this!
    – Nigel
    Commented Jul 27, 2019 at 17:03
  • 3
    If you are wondering why this has an impact, by using *.* you will ignore /etc/nginx/sites-enabled/default, thus not loading the default vhost. Commented Apr 7, 2022 at 4:24
  • This is amazing! It worked for me. And I don't need the default file, so remove the default file, then * worked for me. Thank you all!
    – Hyomin Kim
    Commented Jul 4, 2023 at 5:22
  • I logged in specially to give you up vote! Commented Sep 5, 2023 at 20:52
16

Include sites-available/default in sites-enabled/default. It requires only one line.

In sites-enabled/default (new config version?):

It seems that the include path is relative to the file that included it

include sites-available/default;

See the include documentation.


I believe that certain versions of nginx allows including/linking to other files purely by having a single line with the relative path to the included file. (At least that's what it looked like in some "inherited" config files I've been using, until a new nginx version broke them.)

In sites-enabled/default (old config version?):

It seems that the include path is relative to the current file

../sites-available/default
-1

i had in /sites-availab../ another -enabled folder, so it broke it.

check them out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.