logo
menu

8 Steps to setup Nginx Server on Ubuntu

8-Steps-to-setup-Nginx-Server-on-Ubuntu
Mar 22, 2024
admin

In today's digital landscape, having a robust and reliable web server is essential for anyone venturing into web hosting. Nginx, renowned for its efficiency and scalability, is a popular choice for powering websites of all sizes. If you're using Ubuntu as your server operating system, setting up Nginx is a straightforward process that unlocks a world of possibilities for your online presence.

Initial - Step 1

  • Create an account on a cloud hosting provider like Digital Ocean, AWS, GCP ASURE, CloudFlare
  • Create new instances or droplets (which means your virtual server or computer)
  • Now you are ready to go with the server

Security & Access - Step 2

You can log in to the server using the SSH key or password. If you want to login with a password you can send the password to register email. If you want to log in with SSH then generate the new SSH key or use the existing key you have in your local machine. (We recommended using an SSH key for login)

To generate a key on your local machine

$ ssh-keygen


Press enter and save where you want to save

~/.ssh/id_rsa
~/.ssh/id_rsa.pub


Note: you can change the path but we recommend keeping the public and private keys according to the name of the project or the server you want to setup.

If you already have an SSH key you can copy it directly

$ cat ~/.ssh/id_rsa.pub


Note: the path should be one that you have entered while generating the SSH key

Copy the output and add it to the cloud hosting provider account, You can add the SSH key from the setting of your register account.

Login To Your Server - Step 3

If you do not use SSH keys, it will ask for a password. This is the one that was mailed to you. If you are using the SSH key for login to the server

$ ssh root@<YOUR_SERVER_IP_V4>


Note: Based on the cloud hosting provider we might have different approaches, if the hosting provider provides you pure Ubuntu server you can log in using the above approach while adding the SSH you need to add your username as well.

If you added your username use the following command for login. and follow the Step 7

$ ssh <YOUR_USER_NAME>@<YOUR_SERVER_IP_V4>


Create a new User - Step 4

# adduser <YOUR_USER_NAME>


Give root privileges

# usermod -aG sudo <YOUR_USER_NAME>


Add SSH keys for the new user - Step 5

Now we need to set up SSH keys for the new user you had created on the server. You will need to get them from your local machine

Open a new terminal and copy the SSH key from your local machine.

$ cat ~/.ssh/id_rsa.pub


Now, move to the previous terminal or login to the server using Step 3

Navigate to the new user home folder create a file at '.ssh/authorized_keys' and paste in the key

# cd /home/<YOUR_USER_NAME>
# mkdir .ssh
# cd .ssh
# nano authorized_keys
Paste the key and hit "ctrl-x", hit "y" to save, and "enter" to exit


after you paste your SSH key on the authorized_keys exit from the root login and login with your YOUR_USER_NAME

$ ssh <YOUR_USER_NAME>@<YOUR_SERVER_IP_V4>


Disable root login - Step 6

For security reasons, you have to disable your root login and access the server with a new user or call a safe user.

# sudo nano /etc/ssh/sshd_config


Change the following from the file

PermitRootLogin no
PasswordAuthentication no


If you are login with the password do not disable PasswordAuthentication, It must be yes.

Reload SSH service

# sudo systemctl reload ssh


Simple Firewall Setup - Step 7

# sudo ufw app list


This will show the list of the UFW app if the UFW is not installed then you need to install UFW

# sudo apt install ufw


Allow OpenSSH

# sudo ufw allow OpenSSH


Allow HTTP

# sudo ufw allow http


If you like to run your nginx server in HTTP then you have to allow the HTTP, when you secure the domain using certbot then you can delete the HTTP

Enable firewall

# sudo ufw enable


To check status

# sudo ufw status


Now, that you are done with setups of a simple firewall you can add more policies to the firewall

Software - Step 8

Update packages

# sudo apt update
# sudo apt upgrade


Use the above commands one by one to update and upgrade your Ubuntu server's packages.

Install NGINX

# sudo apt install nginx curl


Nginx Status

sudo systemctl status nginx


Nginx Restart

sudo systemctl restart nginx


If your nginx status is active, you can browse your IP in the browser and see the nginx 404 error.


If you see the 404 error, That's great you setup your server manually

By following these steps, you've successfully set up a basic Nginx server on your Ubuntu machine. Now you have the foundation to set up a server using Nginx and Ubuntu. Remember, security is paramount, so consider implementing additional security measures as needed. As you gain experience, explore more advanced Nginx features to fine-tune your server and optimize performance. Happy Coding!


If you need further assistance or have any questions along the way, feel free to reach out. Happy deploying!

Don't Forget to share this post!
Pace Code
We keep a high velocity in our work to match with the pace of your business and help them grow along, Because we value growing together.
© 2026 Pace Code. All Rights Reserved
Join Our Newsletter
© 2026 Pace Code. All Rights Reserved