Dump the code

Install Nginx on Linux

Created 8 months ago
Posted By admin
3min read
The installation process for Nginx can vary slightly depending on the Linux distribution you are using. Here are instructions for installing Nginx on a few popular Linux distributions:

1. Ubuntu/Debian:
On Ubuntu and Debian-based systems, you can use the package manager to install Nginx:
sudo apt update 
sudo apt install nginx

Once the installation is complete, you can start Nginx and enable it to start on boot:
sudo systemctl start nginx 
sudo systemctl enable nginx

2. CentOS/RHEL:
On CentOS and Red Hat Enterprise Linux (RHEL), you can use the yum package manager:

sudo yum install nginx

Start and enable Nginx:

sudo systemctl start nginx 
sudo systemctl enable nginx

3. OpenSUSE:
On OpenSUSE, you can use the zypper package manager:

sudo zypper install nginx

Start and enable Nginx:

sudo systemctl start nginx 
sudo systemctl enable nginx

Configuration and testing:
After installation, the Nginx configuration files are usually located in the /etc/nginx/ directory. The main configuration file is typically named nginx.conf.

You can test if Nginx is running by opening a web browser and entering your server's IP address or domain name. If Nginx is installed and running, you should see the default Nginx welcome page.

Additional Notes:
  • Firewall: If you have a firewall enabled, you may need to allow traffic on port 80 (HTTP) and/or port 443 (HTTPS) for Nginx.
  • Configuration Files: Nginx's configuration files are located in /etc/nginx/. The main configuration file is nginx.conf, but server blocks (similar to virtual hosts) are often placed in the sites-available directory.
  • Default Document Root: The default document root where web content is served from is usually /usr/share/nginx/html/. You can customize this in the Nginx configuration.
  • SSL Configuration: If you plan to use SSL, additional configuration is needed. You may need to obtain an SSL certificate and configure Nginx to use it.

Remember to consult the official documentation for your specific distribution and Nginx version for any additional details or changes.
Topics

Mastering Nginx

27 articles

Bash script

2 articles

Crontab

2 articles