How to install and use Nginx on OpenSUSE Linux server

last updated in Categories ,

How do I install and configure the latest version of Nginx web server on OpenSUSE Linux server using the CLI and host a static site?

Introduction – Nginx [engine x] is free and open source high-performance web server. It also acts as a reverse proxy server, as well as. This page shows how to install Nginx server on OpenSUSE Linux and configure a static web site.
Tutorial requirements
Operating system/appOpenSUSE Linux
Root privileges requiredYes
DifficultyEasy (rss)
Estimated completion time10m
Table of contents

ADVERTISEMENTS


How to install Nginx on OpenSUSE Linux

The procedure to install Nginx weber server on an OpenSUSE Linux version 15.1/15.2 or Tumbleweed is as follows:

  1. Login to your cloud server or bare metal server using ssh command:
    ssh user@cloud-server-ip
  2. Search for nginx package name using zypper or cnf:
    cnf nginx
    OR
    zypper search nginx
  3. Install nginx package using the zypper command on OpenSUSE:
    sudo zypper update
    sudo zypper install nginx

Let us see all steps, commands and configuration in details for OpenSUSE Linux.

Search for nginx package

Find if nginx web server available on OpenSUSE by running the following cnf command and zypper command:
$ cnf nginx
$ zypper info nginx

OpenSUSE Linux find package contains a nginx web server
Find information about the nginx:
$ sudo zypper info nginx

Loading repository data...
Reading installed packages...


Information for package nginx:
------------------------------
Repository     : Main Update Repository
Name           : nginx
Version        : 1.16.1-lp151.4.11.1
Arch           : x86_64
Vendor         : openSUSE
Installed Size : 2.6 MiB
Installed      : No
Status         : not installed
Source package : nginx-1.16.1-lp151.4.11.1.src
Summary        : A HTTP server and IMAP/POP3 proxy server
Description    : 
    nginx [engine x] is a HTTP server and IMAP/POP3 proxy server written by Igor Sysoev.
    It has been running on many heavily loaded Russian sites for more than two years.

Installing nginx on OpenSUSE Linux

To install Nginx version 1.14.0 (latest stable in OpenSUSE), run the following zypper command:
$ sudo zypper install nginx

Command to Install and use Nginx on OpenSUSE Linux server
Installing nginx using zypper command

How to start, stop, restart the Nginx server on OpenSUSE

Use the systemctl command:
$ sudo systemctl start nginx ## <-- start the service ##
$ sudo systemctl restart nginx ## <-- restart the service ##
$ sudo systemctl stop nginx ## <-- stop the service ##
$ sudo systemctl status nginx ## <-- Get the status of the service ##

How to enable the Nginx service at boot time on OpenSUSE

Again run the following systemctl command:
$ sudo systemctl enable nginx.service
Start it:
$ sudo systemctl start nginx.service
How to start, stop, restart the Nginx on OpenSUSE Linux server
Verify that nginx is running using the ss command and TCP port 80 is open:
$ sudo ss -tulpn | grep nginx

tcp    LISTEN     0      128    0.0.0.0:80                 0.0.0.0:*                   users:(("nginx",pid=20511,fd=6),("nginx",pid=20510,fd=6))

Configuring nginx on OpenSUSE server

Let us create a sample index.html file in /srv/www/htdocs using a text editor such as vim command:
$ sudo vi /srv/www/htdocs/index.html
Append the following html:

<html>
        <head>
                <title>OpenSUSE Linux - Nginx Server by NixCraft</title>
        </head>
        <body>
                <h1>Welcome</h1>
                <p>This is a test server for static files.</p>
                <hr>
                <small>Powered by nginx and OpenSUSE Linux server</small>
        </body> 
</html>

Save and close the file in vim text editor. Use the ip command and grep command to find out your server IP address
$ ip a s
$ ip a s eth0
$ ip a s eth0 | grep -w inet

inet 192.168.2.133/24 brd 139.162.28.255 scope global eth0

Fire a web browser and type url:
http://server-ip/
http://192.168.2.133/

Testing Nginx on OpenSUSE Linux

Configure Nginx server

Important files and directory to configure Nginx on OpenSUSE Linux:

  • Config dir – /etc/nginx/
  • Master/Global config file – /etc/nginx/nginx.conf
  • Default TCP ports opened by Nginx – 80 (HTTP), 443 (HTTPS)
  • Document root directory – /srv/www/htdocs/
  • Virtual host domain config dir – /etc/nginx/vhosts.d/

To edit files use a text editor such as vi:
$ sudo vi /etc/nginx/nginx.conf
You can upload or copy your html/css/js and images to /srv/www/htdocs/:
$ cd /srv/www/htdocs/
$ sudo cp /backups/your-domain/*.html .
$ sudo cp /backups/your-domain/*.css .
$ sudo cp /backups/your-domain/*.png .

OR Copy from local desktop to the remote server using the rsync command or sftp command:
$ rsync -avP ~/projects/static/your-domain/* root@192.168.2.133:/srv/www/htdocs/

Open TCP port 80 and 443 using firewalld

Run the following command to find your default zone:
sudo firewall-cmd --get-default-zone
Sample outputs:

public

Next, open TCP port 80 (http) for public zone:
sudo firewall-cmd --zone=public --add-service=http --permanent
Run same command but for TCP port 443 (https):
sudo firewall-cmd --zone=public --add-service=https --permanent
Finally, reload the firewall, run:
sudo firewall-cmd --reload
See “How to set up a firewall using FirewallD on OpenSUSE Linux” for more info.

Install additional nginx modules

Use the following command to search additional modules to enhance Nginx server featues:
$ sudo zypper search nginx

Loading repository data...
Reading installed packages...
 
S  | Name                                   | Summary                                                                         | Type
---+----------------------------------------+---------------------------------------------------------------------------------+-----------
   | dehydrated-nginx                       | Nginx Integration for dehydrated                                                | package
i  | nginx                                  | A HTTP server and IMAP/POP3 proxy server                                        | package
   | nginx                                  | A HTTP server and IMAP/POP3 proxy server                                        | srcpackage
   | nginx-geolite-asn                      | IP ASN geolocation databases for nginx                                          | package
   | nginx-geolite-city                     | Free IP city geolocation databases for nginx                                    | package
   | nginx-geolite-country                  | Free IP country geolocation databases for nginx                                 | package
   | nginx-ingress-controller               | Kubernetes ingress controller for nginx                                         | package
i+ | nginx-module-brotli                    | NGINX module for Brotli compression                                             | package
   | nginx-module-cookie-flag               | The Nginx module for adding cookie flag                                         | package
   | nginx-module-devel-kit                 | Additional generic tools for nginx module development                           | package
   | nginx-module-devel-kit-source          | The nginx-module-devel-kit source                                               | package
   | nginx-module-http-auth-digest          | Digest Authentication for Nginx                                                 | package
   | nginx-module-http-substitutions-filter | Regular expression and fixed string substitutions nginx filter module           | package
   | nginx-module-modsecurity               | ModSecurity v3 Nginx Connector                                                  | package
   | nginx-module-set-misc                  | Various set_xxx directives added to nginx's rewrite module                      | package
   | nginx-module-sticky-ng                 | Nginx module to add a sticky cookie to be forwarded to the same upstream server | package
   | nginx-module-vts                       | Nginx virtual host traffic status module                                        | package
   | nginx-source                           | The nginx source                                                                | package
   | pcp-pmda-nginx                         | Performance Co-Pilot (PCP) metrics for the Nginx Webserver                      | package
   | python-certbot-nginx                   | Nginx plugin for Certbot                                                        | srcpackage
   | python2-certbot-nginx                  | Nginx plugin for Certbot                                                        | package
   | python3-certbot-nginx                  | Nginx plugin for Certbot                                                        | package
   | rubygem-passenger-nginx                | Passenger Nginx module                                                          | package
   | vim-plugin-nginx                       | VIM support for nginx config files                                              | package

For example, one can install ModSecurity module as follows:
$ sudo zypper in nginx-module-modsecurity

Conclusion

In the next part of the series, you will learn how to install the latest version of PHP 7.x.x on OpenSUSE Linux server and secure communication with TLS/SSL certificates. For more info on nginx config see this page here.

This entry is 1 of 3 in the OpenSUSE Linux LEMP Stack Tutorial series. Keep reading the rest of the series:
  1. Install and use Nginx on OpenSUSE Linux
  2. Secure Nginx with Let's Encrypt on OpenSUSE Linux
  3. Install PHP on OpenSUSE Linux 15.2/15.1

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.


ADVERTISEMENTS

Leave a Comment