YouTip LogoYouTip

Nginx Tutorial - Getting Started

Introduction

Nginx is a high-performance web server and reverse proxy. It powers some of the busiest websites in the world and is known for its stability, rich feature set, and low resource consumption.

Installation

# Ubuntu/Debian
sudo apt update
sudo apt install nginx

# Start and enable
sudo systemctl start nginx
sudo systemctl enable nginx

# Check status
sudo systemctl status nginx

Basic Configuration

The main configuration file is located at /etc/nginx/nginx.conf. Site configs go in /etc/nginx/sites-available/.

# /etc/nginx/sites-available/mysite
server {
    listen 80;
    server_name example.com;
    root /var/www/html;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}

Essential Commands

# Test configuration
sudo nginx -t

# Reload without downtime
sudo nginx -s reload

# Stop gracefully
sudo nginx -s quit

# Enable a site
sudo ln -s /etc/nginx/sites-available/mysite /etc/nginx/sites-enabled/

Summary

Nginx is a versatile web server. Start with basic server blocks, learn nginx -t to test configs, and use nginx -s reload for zero-downtime updates.

← Nginx Reverse ProxyGit Remote Operations β†’