4

I would like to split my nginx websites configuration in multiples files and I have a problem.

So I have 3 files in /etc/nginx/sites-available folder and i created their symbolic links in /etc/nginx/site-enabled with these commands :

ln -s /etc/ngnix/sites-available/site1 /etc/nginx/sites-enabled/site1
ln -s /etc/ngnix/sites-available/site2 /etc/nginx/sites-enabled/site2
ln -s /etc/ngnix/sites-available/site3 /etc/nginx/sites-enabled/site3

I restarted and reloaded nginx, but it don't work.

The strange thing is that when i copy with cp command the files, its works.

I checked the permissions and its looks like good ( rw-r--r-- for all).

Maybe I must chown these files with specific user ( www-data ?) instead of root:root ?

root@lenouvel:/etc/nginx# ls -la sites-available/
total 20
drwxr-xr-x 2 root root 4096 Jul 27 17:36 .
drwxr-xr-x 5 root root 4096 Jul  9 14:19 ..
-rw-r--r-- 1 root root 1404 Jul 27 17:50 default
-rw-r--r-- 1 root root 2165 Jul 27 17:40 gitlab
-rw-r--r-- 1 root root 1317 Jul 27 17:33 roundcube

root@lenouvel:/etc/nginx# ls -la sites-enabled/
total 8
drwxr-xr-x 2 root root 4096 Jul 27 20:17 .
drwxr-xr-x 5 root root 4096 Jul  9 14:19 ..
lrwxrwxrwx 1 root root   23 Jul 27 20:16 default -> sites-available/default
lrwxrwxrwx 1 root root   22 Jul 27 20:17 gitlab -> sites-available/gitlab
lrwxrwxrwx 1 root root   25 Jul 27 20:17 roundcube -> sites-available/roundcube

nginx.conf :

root@lenouvel:/etc/nginx# cat nginx.conf 
user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {
##
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

gzip on;
gzip_disable "msie6";

# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##

#include /etc/nginx/naxsi_core.rules;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
LnlB
  • 180
  • 2
  • 11
  • You added to the configuration file nginx.conf string `include /etc/nginx/sites-enabled/*.conf; or include /etc/nginx/sites-enabled/*;` ? – Rhim Jul 27 '14 at 17:39
  • yes it is in http section and not commented – LnlB Jul 27 '14 at 17:56
  • Show command output `ls -la /etc/nginx/sites-enabled/` and `ls -la /etc/ngnix/sites-available/` and `cat /you_path_to_nginx.conf` – Rhim Jul 27 '14 at 18:14
  • `default -> sites-available/default` and be `default -> ../sites-available/default` `cd /etc/nginx/sites-enabled/; ln -s ../sites-available/roundcube .` – Rhim Jul 27 '14 at 19:23
  • Finally I retry with absolute paths and its works. I don't understand why it don't work when I create symbolic link with relative path... – LnlB Jul 27 '14 at 19:33
  • `roundcube -> sites-available/roundcube` yours symlink path to `/etc/nginx/sites-enabled/sites-available/roundcube` – Rhim Jul 27 '14 at 19:40
  • ah you're right, i understand now ! Thank you very much Rhim :) – LnlB Jul 27 '14 at 19:43
  • No-one commented on the permisions, though. Should `root` be the owner of nginx related configuration files? – Nikos Alexandris Dec 06 '15 at 12:02
  • 1
    @NikosAlexandris, this is old but I stumbled on this unanswered question and found a useful answer on another [SO question](https://stackoverflow.com/questions/41736236/nginx-configuration-permissions-and-ownership) `As a note, generally all files in /etc/ should be owned as root:root and generally 744 unless security-critical to prevent dangerous tampering by users or exploited services.` – avn Sep 29 '20 at 08:40

0 Answers0