sudo apt-get update
sudo apt-get install nginx
sudo /etc/init.d/nginx {command} // or sudo service nginx {command}
nginx {start|stop|restart|reload|force-reload|status|configtest|rotate|upgrade}
Add directory, set rights and create index.html
sudo mkdir -p /var/www/example.com/html
sudo chown -R {USER}:{USER} /var/www/example.com/html
nano /var/www/example.com/html/index.html
Add html markup INto index.html
<html>
<head>
<title>Welcome to Example.com!</title>
</head>
<body>
<h1>Success! The example.com server block is working!</h1>
</body>
</html>
Copy sample of virtual host
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/example.com
Edit virtual host params
sudo nano /etc/nginx/sites-available/example.com
Minimal required options: port
, root
, index
, server_name
and location
server {
listen 80;
listen [::]:80;
root /var/www/example.com/html;
index index.php index.html index.htm;
server_name example.com www.example.com;
location / {
try_files $uri $uri/ =404;
}
}
Enabe virtual host
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo /etc/init.d/nginx reload
Open hosts file
sudo nano /etc/hosts
Add domain
127.0.0.1 example.com www.example.com
http://example.com