Ubuntu - Nginx
Ubuntu - Nginx: Modern Web Serving
Section titled “Ubuntu - Nginx: Modern Web Serving”Nginx (pronounced “engine-ex”) is a high-performance, open-source web server. It’s renowned for its stability, rich feature set, simple configuration, and low resource consumption. Originally designed as a web server, Nginx is now also widely used as a reverse proxy, load balancer, mail proxy, and HTTP cache. This chapter will guide you through installing and verifying Nginx on your Ubuntu system.
To install Nginx, follow these steps:
Step 1 − Open your terminal. It’s good practice to update your package list before installing new software. This ensures you get the latest available versions.
sudo apt updateThis command refreshes the local list of available packages from the repositories configured on your system. You’ll see lines of output indicating which repositories are being checked.
Step 2 − Next, install Nginx using the following command:
sudo apt install nginxThe system will ask for your password and then show you the packages that will be installed and the disk space they’ll occupy. Type ‘Y’ and press Enter to confirm the installation. The package manager will then download and install Nginx and its dependencies.
Step 3 − Once the installation is complete, Nginx should start automatically. You can verify its status using systemd:
sudo systemctl status nginxIf Nginx is running correctly, you should see output indicating that the service is ‘active (running)’. Press ‘q’ to exit the status view.
You can also manage Nginx with other systemctl commands:
- To stop Nginx:
sudo systemctl stop nginx - To start Nginx:
sudo systemctl start nginx - To restart Nginx (e.g., after a configuration change):
sudo systemctl restart nginx - To reload Nginx (applies configuration changes without dropping connections):
sudo systemctl reload nginx - To enable Nginx to start on boot:
sudo systemctl enable nginx - To disable Nginx from starting on boot:
sudo systemctl disable nginx
Step 4 − To confirm Nginx is serving pages, open a web browser and navigate to http://localhost or http://YOUR_SERVER_IP (replace YOUR_SERVER_IP with your server’s actual IP address). You should see the default Nginx welcome page, typically saying something like “Welcome to nginx!”
Alternatively, from the terminal, you can use curl:
curl http://localhostThis should output the HTML source of the Nginx welcome page.
Nginx configuration files are primarily located in /etc/nginx/. The main configuration file is /etc/nginx/nginx.conf. Server block configurations (similar to virtual hosts in Apache) are typically stored in /etc/nginx/sites-available/ and enabled by creating symbolic links in /etc/nginx/sites-enabled/.
You now have a functional Nginx web server running on your Ubuntu system, ready to host websites or act as a reverse proxy. For more detailed configuration, refer to the official Nginx documentation.