Blog

03/06/2019

How to install and use Nginx on OpenSUSE Linux server



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.

How to install Nginx on OpenSUSE Linux

The procedure to install Nginx weber server on an RHEL 7 or CentOS Linux 7 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
  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.

kbd { display: inline-block; margin: 0 .1em; padding: .1em .6em; font-family: Arial,”Helvetica Neue”,Helvetica,sans-serif; font-size: 11px; line-height: 1.4; color: #242729; text-shadow: 0 1px 0 #FFF; background-color: #e1e3e5; border: 1px solid #adb3b9; border-radius: 3px; box-shadow: 0 1px 0 rgba(12,13,14,0.2), 0 0 0 2px #FFF inset; white-space: nowrap;}

Search for nginx package

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

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

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))

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>

<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/

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/

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.

(adsbygoogle = window.adsbygoogle || []).push({});

Posted by: SXI ADMIN

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.

14/08/2019

How to KVM, QEMU start or stop virtual machine from command line (CLI)

KVM or Kernel Based Virtual Machine is a popular virtualization technology. It allows you to run virtual guest machines over a host machine. To start...
14/08/2019

How to Docker backup Saving and restoring your volumes

Running a Docker volume backup First, we spin up a temporary container, and we mount the backup folder and the target Docker volume to this container....
12/08/2019

How to Start and Enable Firewalld on CentOS 7

In this article, we discuss how to start and enable firewalld. It is highly recommended that you have a firewall protecting your server.Pre-Flight CheckThese...