setup webserver using nginx in ubuntu

·

1 min read

sudo apt install nginx
sudo systemctl status nginx

open file /etc/nginx/nginx.conf and comment below line

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

to setup a new website, create a file in /etc/nginx/sites-available/. Filename should be same to domain. For instance, if site name is abc.com, then we will name the file as 'abc.com.conf'

server {
        listen 80;
        server_name abc.com;

        location / {
                root /var/www/test-ssl;
                index index.html index.htm;
        }

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

}

create symbolic link

sudo ln -s /etc/nginx/sites-available/abc.com.conf /etc/nginx/sites-enabled/abc.com.conf

to check if our configuration is ok, run this command

sudo nginx -t

if everything goes well, reload nginx

sudo nginx -s reload