Adding new website to Nginx
Published on: 12th Jan 2023
Updated on: 12th Jan 2023
Here's the step
Without the help on using cPanel or any other server management tool, you will need the following steps in adding a new website.
-
To add user, run the following command and it will create user record and an user directory in
/home
,sudo useradd user1
-
To set password for the user, run the following command and then key in the password,
sudo passwd user1
-
To add user to a group,
sudo usermod -G www-data -a user1
-
To change user's home directory,
sudo usermod -d /home/user1 -m user1
-
If the web directory is accessible by the FTP user, you may have to set the access permission.
sudo mkdir /home/user1/domain2-com sudo chown -R user1:www-data /home/user1 sudo chmod -R 0755 /home/user1 sudo chmod g+s /home/user1
Notes: where 'user1' is the user ID and 'www-data' is the group. Notes: where 'chmod g+s' set the current ACL to be inherited to the new files.
-
You may also set the quota for the user. In the following example, I'll allocate 1GB storage space to user1 account.
sudo setquota -u user1 1G 1.2G 0 0 /
NOTES: the first 1G is the soft limit and then the 1.2G is the hard limit. The last two zero is to limit by the number of files.
-
To disable the shell access for the user, you have to change the shell setting for the user account:
sudo usermod -s /usr/sbin/nologin user1
-
To enable the user accessing the FTP, add 'user1' into the following file
sudo nano /etc/vsftpd.userlist
-
To create 'domain2.com' file in
/etc/nginx/sites-available
.server { server_name domain2.com www.domain2.com; root /home/user1/domain2-com; index index.htm index.html; access_log /var/log/nginx/domain2.log; location / { try_files $uri $uri/ =404; } }
-
To enable the new website:
sudo ln -s /etc/nginx/sites-available/domain2.com /etc/nginx/sites-enabled/
-
Test the configuration and restart Nginx.
sudo nginx -t sudo systemctl restart nginx
-
To enable SSL cert for this new website, run the certbot command to add it:
certbot --nginx -d domain2.com,www.domain2.com
References
Jump to #UBUNTU blog
Author
Lau Hon Wan, software developer.