Nginx is one of the top open-source web server and an HTTP load balancer. It is also used as a reverse proxy server and an HTTP cache. Nginx has gained popularity since its release because of its efficient resource utilization and responsiveness under load. It is faster at delivering static content while consuming fewer resources.
Here at Ibmi Media, we shall look into how to install Nginx on openSUSE Leap 15.3 system via different ways.
Note: To install Nginx, you will require sudo privileges. Also, make sure that no Apache or other process is listening on ports 80 or 443.
You can learn how to install Nginx on Ubuntu and CentOS, if you are running these Linux distributions.
Follow the below steps to install Nginx available in the openSUSE default repositories:
1. Run the command below to refresh / Update your system repositories:
$ sudo zypper refresh
2. Then run the command below to install Nginx on your openSUSE system:
$ sudo zypper install nginx
Then you'll be given details about installation, such as the packages that will be installed on your openSUSE system, their overall download size, and the disk space that will be used. After providing the details, you'll be asked to confirm if you wish to carry on the procedure. Hit y and then the Return key to carry on.
Now Nginx will be installed on your openSUSE system.
3. Run the command below to enable the Nginx service:
$ sudo systemctl enable nginx
Then start the Nginx service through the below command:
$ sudo systemctl start nginx
To verify the status of Nginx, run the below command:
$ sudo systemctl status nginx
The output will indicate that the Nginx service is running, if everything is alright.
To view the version of the Nginx package installed on your openSUSE system, run the below command:
$ sudo nginx -v
Here, we will install Nginx by adding the repository available at the openSUSE website. Through this method, you can have an updated version of Nginx on your system.
Now, follow the following steps:
1. To install the newest version of Nginx on your openSUSE, add the repository using the below command:
$ sudo zypper addrepo https://download.opensuse.org/repositories/server:http/openSUSE_Leap_15.3/server:http.repo
2. After adding the repository, run the below command to refresh the local repository index:
$ sudo zypper refresh
This command will prompt you to accept or reject the GPG key for the repository you have added. Type a and hit Enter to accept the GPG key.
3. Now you can install Nginx latest version through the below command:
$ sudo zypper install nginx
Then you'll be given information about Nginx installation, such as the packages that will be installed on your openSUSE system, their overall download size, and the disk space that will be used. After giving the information, you will be asked to confirm if you wish to carry on the procedure. Hit y and then the Return key to carry on.
Now Nginx will be installed on your openSUSE system.
4. Run the command below to enable the Nginx service:
$ sudo systemctl enable nginx
Then start the Nginx service through the command below:
$ sudo systemctl start nginx
To verify the status of Nginx, run the command below:
$ sudo systemctl status nginx
The output will indicate that the Nginx service is running.
To view the version of the Nginx package installed on your openSUSE system, run the command below:
$ sudo nginx -v
You will also need to configure the firewall to open the http and https ports used by Nginx.
To find the default zone in your firewall, run the command below:
$ sudo firewall-cmd --get-default-zone
In the output, you can find out your firewall's default zone.
Then use the command below to open http port in your firewall:
$ sudo firewall-cmd --permanent --zone=public --add-service=http
Use the command below to open https port in your firewall:
$ sudo firewall-cmd --permanent --zone=public --add-service=https
You can replace "public" zone with the zone that is currently set as your default zone.
Then to apply the changes, run the command below:
$ sudo firewall-cmd --reload
1. Now to test Nginx server, create an index.html file in the /srv/www/htdocs folder:
$ sudo nano /srv/www/htdocs/index.html
2. Add below lines in the index.html file:
html>
<body>
<h1>......Welcome to NGINX!......</h1>
</body>
</html>
3. Save and close the index.html file.
4. Restart the Nginx service through the command below:
$ sudo systemctl restart nginx
5. Now launch any web browser on your system and type localhost or your IP address in the address bar. If Nginx is installed correctly, you will see the "Welcome to NGINX!" page.
Ideally, you would want to run your Nginx on HTTPS using an SSL certificate. The best way to do this is to use Let’s Encrypt, a free, automated, and open certificate authority run by the nonprofit Internet Security Research Group (ISRG).
1. Install the certbot package as follows:
$ sudo zypper install python3-certbot-nginx
2. Once installed, run the following command to start the creation of your certificate:
$ sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --email you@example.com -d www.example.com
This ideal setup includes force HTTPS 301 redirects, a Strict-Transport-Security header, and OCSP Stapling. Just make sure to adjust the e-mail and domain name to your requirements.
Now your URL will be HTTPS://www.example.com instead of HTTP://www.example.com.
If you use the old HTTP URL, it will automatically redirect to HTTPS.
3. Optionally, you can set a cron job to renew the certificates automatically. Certbot offers a script that does this automatically, and you can first test to make sure everything is working by performing a dry run:
$ sudo certbot renew --dry-run
4. If everything is working, open your crontab window using the following terminal command:
$ sudo crontab -e
5. Next, specify the time when it should auto-renew. This should be checked daily at a minimum, and if the certificate needs to be renewed, the script will not update the certificate:
00 00 */1 * * /usr/sbin/certbot-auto renew
To save, press the ESCAPE KEY and then type :wq! to save the file. Alternatively, to exit without saving, type :qa!
If you ever need to uninstall Nginx, you can do so using the below command:
$ sudo zypper remove nginx
If prompted, enter the sudo password. Then it will mention you the packages that will be uninstalled from your openSUSE system and the disk space that will be freed. Then you'll be asked to confirm if you wish to carry on the procedure. Hit y and then the Return key to remove Nginx from your openSUSE system.
This article covers how you can easily install Nginx on your openSUSE system. In fact, Nginx or engine x is a high-performance HTTP- and proxy server with low memory consumption. It is used by large scale websites like Netflix, Pinterest, CloudFlare , Github etc. Nginx has an easy to learn configuration syntax and can act also as a load balancer with health checks and reverse proxy with caching features.
You can Install Nginx with the "zypper in" command:
$ zypper in nginx
Start nginx and enable it to be started at boot time:
$ systemctl start nginx
$ systemctl enable nginx