Congratulations! You've successfully installed Nginx. Now, let's make sure everything is working as expected and explore some fundamental operations. This section will guide you through verifying your installation and performing basic checks to ensure your Nginx server is up and running.
The first and most crucial step is to check if the Nginx process is running. You can do this using your system's service management tools. The specific command might vary slightly depending on your operating system (e.g., systemctl on modern Linux distributions, service on older ones, or even launchctl on macOS).
sudo systemctl status nginxIf Nginx is running correctly, you should see output indicating its active status. Look for lines like 'Active: active (running)' or similar. If it's not running, you'll typically see 'inactive (dead)' or an error message. In that case, you can try starting it with sudo systemctl start nginx.
Next, we'll verify that Nginx is listening on its default port, which is port 80 for HTTP. This confirms that the web server is ready to accept incoming connections.
sudo netstat -tulnp | grep nginxThis command will show you network connections. You should see a line indicating that Nginx is listening on port 80 (often displayed as 0.0.0.0:80 or :::80). The -tulnp flags ensure we see TCP listening ports, numeric addresses, and the associated process name.
The most direct way to confirm your Nginx installation is to visit it from your web browser. Open your browser and navigate to your server's IP address or hostname. If you're running Nginx on your local machine, you can usually use http://localhost or http://127.0.0.1.
You should see the default Nginx welcome page. This page is served from the default Nginx configuration file and confirms that your web server is accessible from the outside world (or your local network).
It's also a good practice to check the Nginx configuration syntax. This helps catch any errors before they cause issues when you try to reload or restart Nginx.
sudo nginx -tThis command will test the Nginx configuration files. If everything is syntactically correct, you'll see messages indicating that the test is successful and the configuration file has been loaded.
Finally, let's look at how to manage the Nginx service. Knowing these commands is essential for everyday operations.
graph TD
A[Start Nginx] --> B{Nginx Running?};
B -- Yes --> C[Stop Nginx];
B -- No --> D[Start Nginx];
C --> E{Nginx Stopped?};
E -- Yes --> F[Start Nginx];
E -- No --> G[Restart Nginx];
D --> H{Nginx Running?};
H -- Yes --> I[Reload Nginx];
H -- No --> J[Error];
I --> K[Configuration Loaded];
G --> L[Configuration Reloaded];
F --> M[Nginx Service Managed];
Here are the common commands to manage the Nginx service:
- Start Nginx:
sudo systemctl start nginx - Stop Nginx:
sudo systemctl stop nginx - Restart Nginx:
sudo systemctl restart nginx(stops and then starts the service) - Reload Nginx:
sudo systemctl reload nginx(gracefully reloads configuration without interrupting active connections) - Check Status:
sudo systemctl status nginx - Enable on Boot:
sudo systemctl enable nginx - Disable on Boot:
sudo systemctl disable nginx
By completing these verification steps, you've confirmed that Nginx is installed correctly and is ready to serve your web content. You've also gained the fundamental knowledge to manage the Nginx service.