Support Online
Skip to main content

Nginx Installation: Fast and Secure Web Server on Ubuntu

In this guide, you will learn how to install Nginx on Ubuntu servers, basic configuration and production-appropriate settings.
The steps are simple, applicable and suitable for live systems.

What Will You Learn in This Guide?

  • Installing Nginx on Ubuntu
  • Opening secure access with UFW
  • Managing the service with systemd
  • Creating a server block (virtual host)
  • Basic security and performance settings

Technical Summary (Phase 1)

This guide describes installing Nginx web server on Ubuntu 22.04, 24.04 and 25.04.
The goal is to prepare a secure and high-performance web server.


1. Step: Nginx Installation

Update the system packages first.

sudo apt update
sudo apt upgrade -y
  • This command updates your system.


sudo apt install nginx -y
  • This command installs Nginx.

2. Step: Firewall Setting (UFW)

  1. List Nginx profiles in UFW.

sudo ufw app list

  1. Allow only HTTP traffic.

sudo ufw allow 'Nginx HTTP'

  1. Check the firewall status.

sudo ufw status

3. Step: Checking Nginx Service

  1. Check if Nginx is running.

systemctl status nginx
  • This command verifies that the service is active.

Go to your server IP from the browser:


http://sunucu_ip
  • You should see the default Nginx page.

4. Step: Nginx Service Management

  1. To stop Nginx:

sudo systemctl stop nginx

  1. To start:

sudo systemctl start nginx

  1. To reboot:

sudo systemctl restart nginx

  1. To refresh the setting without disconnecting:

sudo systemctl reload nginx

5. Step: Creating Server Block (Virtual Host)

  1. Create a directory for your domain.

sudo mkdir -p /var/www/ornek.com/html
  1. Set directory ownership.

sudo chown -R $USER:$USER /var/www/ornek.com
sudo chmod -R 755 /var/www/ornek.com

  • Create a test page.

nano /var/www/ornek.com/html/index.html

<h1>Nginx başarıyla çalışıyor</h1>
  • Create the server block file.

sudo nano /etc/nginx/sites-available/ornek.com


server {
listen 80;
server_name ornek.com www.ornek.com;

root /var/www/ornek.com/html;
index index.html;

location / {
try_files $uri $uri/ =404;
}
}
  • This configuration matches the domain name to the content.

  • Activate it.

sudo ln -s /etc/nginx/sites-available/ornek.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx

6. Step: Security and Performance Settings

  1. Open the main configuration file.

sudo nano /etc/nginx/nginx.conf

  1. Add the following settings.

server_tokens off;
worker_processes auto;

  1. Turn on gzip compression.

gzip on;
gzip_comp_level 6;
gzip_types text/plain text/css application/javascript application/json;
  • These settings provide speed and security.

Frequently Asked Questions (FAQ)

  1. Why is Nginx faster than Apache? It uses event-based architecture and consumes less resources.

  2. Does Nginx start automatically? Yes, it is active by default with systemd.

  3. Can I host multiple sites? Yes, a separate server block is used for each site.

  4. Where should I look if I get an error? Examine /var/log/nginx/error.log.


Result

You now have a secure and fast Nginx web server running on your Ubuntu server. This structure provides a solid foundation for live projects.

You can create your infrastructure on the GenixNode platform in minutes to immediately use Nginx on high-performance servers.