Nginx Virtual Hosts on Ubuntu
1. Create Root Directory
sudo mkdir -p /var/www/login.jordan.app/html
sudo chown -R $USER:$USER /var/www/login.jordan.app/html
sudo chmod -R 755 /var/www/login.jordan.app
2. Creating Sample Pages
vi /var/www/login.jordan.app/html/index.html
<html>
<head>
<title>Welcome to login.jordan.app!</title>
</head>
<body>
<h1>Success! The jordan.app server block is working!</h1>
</body>
</html>
3. Create Block Files
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/login.jordan.app
sudo vi /etc/nginx/sites-available/login.jordan.app
server {
listen 80;
listen [::]:80;
root /var/www/login.jordan.app/html;
index index.html index.htm index.nginx-debian.html;
server_name jordan.app www.jordan.app login.jordan.app;
location / {
try_files $uri $uri/ =404;
}
}
grep -R default_server /etc/nginx/sites-enabled/
4. Enabling Server Block
sudo ln -s /etc/nginx/sites-available/login.jordan.app /etc/nginx/sites-enabled/
5. Modify config file
sudo vi /etc/nginx/nginx.conf
Remove the # symbol to uncomment
server_names_hash_bucket_size 64;
sudo nginx -t
6. Restart
sudo systemctl restart nginx
7. Modify host file
sudo vi /etc/hosts
3.104.250.177 jordan.app www.jordan.app login.jordan.app