Skip to content

Instantly share code, notes, and snippets.

Last active November 15, 2021 08:10
What would you like to do?
Adding sites-available and sites-enabled on NginX

Adding sites-available and sites-enabled on NginX

If you install official version of Nginx from their repository, you'll find that there was no any sites-available and sites-enabled directory like in Apache. Good news is, you can add it yourself !

  1. Create a new directory under /etc/nginx.
sudo mkdir /etc/nginx/sites-{available,enabled}
  1. Append below line
include /etc/nginx/sites-enabled/*; #APPEND THIS

To /etc/nginx/nginx.conf, so the block would look like.

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

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*; #APPEND THIS
  1. Make sure your configuration is okay and doesn't throw any error, test it.
$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
  1. If you want to enable a sites manually, you can do so by symlink it to sites-enabled directory/
sudo ln -s /etc/nginx/sites-available/{yoursite} /etc/nginx/sites-enabled/{yoursite}temp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment