nginx配置目录结构

在ubuntu和debian中通过apt-get安装了nginx之后,默认的位置是在

/etc/nginx$ ls
conf.d          koi-utf     modules-available  proxy_params     sites-enabled  win-utf
fastcgi.conf    koi-win     modules-enabled    scgi_params      snippets
fastcgi_params  mime.types  nginx.conf         sites-available  uwsgi_params

其中配置文件的入口是nginx.conf这个文件;

打开这个文件可以看到:

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
}

http {
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;

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


    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

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



    gzip on;
    gzip_disable "msie6";



    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

把注释删掉就是上面这个样子

其中有两行比较重要

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

第一行表示把/etc/nginx/conf.d/这个目录下面所有以conf结尾的文件都当做配置文件引入;
第二行表示把/etc/nginx/sites-enabled/下面所有的文件都当成配置文件引入;

我们看下 /etc/nginx/sites-enabled/ 这个目录

/etc/nginx$ ls  -alh sites-enabled/
total 8.0K
drwxr-xr-x 2 root root 4.0K Dec 12 20:08 .
drwxr-xr-x 8 root root 4.0K Dec 12 20:08 ..
lrwxrwxrwx 1 root root   34 Dec 12 20:08 default -> /etc/nginx/sites-available/default

发现所有文件都是从/etc/nginx/sites-available创建的软链接,而sites-available/文件夹里面是实实在在的配置文件

ls -alh sites-available/
total 12K
drwxr-xr-x 2 root root 4.0K Dec 12 20:22 .
drwxr-xr-x 8 root root 4.0K Dec 12 20:08 ..
-rw-r--r-- 1 root root 2.4K Dec 12 20:22 default

就此我们可以总结出来,sites-available/ 是用来放置配置文件的,而sites-enabled/是用来放置上线了的配置文件的。

你可能感兴趣的:(nginx配置目录结构)