How To Install Nginx on SUSE Linux Enterprise server 12

in Categories , last updated February 9, 2018

How do I install and setup Nginx server on SuSe Enterprise Linux server (SLES) version 12 SP 3?

Nginx is free and open source software. It is a very popular web server. You can replace Apache web server and use Nginx to host static, a dynamic site and a reverse proxy server for Apache. This page shows you how to install Nginx on your SUSE Linux Enterprise Server version 12.0 SP2 or SP3.

Step 1 – Configure Nginx repo

Type the following zypper command to add the zypper repository for SLES:
$ sudo zypper addrepo -G -t yum -c 'http://nginx.org/packages/sles/12' nginx
Add Pre-Built SLES Packages Repo for Stable Nginx version
Next, you must verify digital signatures to maintain the integrity and origin of the downloaded package. Grab nginx signing key using the wget command:
$ wget http://nginx.org/keys/nginx_signing.key
Sample outputs:

--2018-02-03 23:48:48--  http://nginx.org/keys/nginx_signing.key
Resolving nginx.org (nginx.org)... 206.251.255.63, 95.211.80.227, 2001:1af8:4060:a004:21::e3, ...
Connecting to nginx.org (nginx.org)|206.251.255.63|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1561 (1.5K) [text/plain]
Saving to: ‘nginx_signing.key’
 
100%[==================================================>] 1,561       --.-K/s   in 0s      
 
2018-02-03 23:48:49 (117 MB/s) - ‘nginx_signing.key’ saved [1561/1561]

Import key to the rpm using the rpm command:
$ sudo rpm --import nginx_signing.key

Step 2 – How to install Nginx on SUSE Linux

Type the following zypper command:
$ sudo zypper install nginx
How To Install Nginx on SUSE Linux using zypper command

Step 3 – Setup the Firewall/Open port 80

First create Nginx service specific configuration file to open port 80 using a text editor such as vi command
$ sudo vi /etc/sysconfig/SuSEfirewall2.d/services/nginx
Append the following configuration:

## Name: Nginx web server
## Description: Open ports for Nginx Server
 
# space separated list of allowed TCP ports
TCP="http"

Since I haven not configured SSL certificate for my server yet, I will only need to allow traffic on TCP port number 80. Save and exit the vi/vim text editor. Now, simply run the following command to open port 80:
$ sudo yast firewall
You must use the TAB and arrow keys to navigate YaST. In YaST, navigate to Allowed Services, and then press the Enter key:
SLES Firewall Config for Nginx server
Use the TAB to navigate to Service to Allow and press Down arrow key to select Nginx web server, and then press the Enter key. You must press Alt-A to add Nginx server to firewall:
Adjust the SUSE Linux Firewall for Nginx
Press Alt-N and Alt-F to save and finish the firewall settings on SLES. Once returned to the shell prompt, list list all iptables rules on SLES:
$ sudo iptables -S
Sample outputs:

-A input_ext -p tcp -m limit --limit 3/min -m tcp --dport 80 --tcp-flags FIN,SYN,RST,ACK SYN -j LOG --log-prefix "SFW2-INext-ACC-TCP " --log-tcp-options --log-ip-options
-A input_ext -p tcp -m tcp --dport 80 -j ACCEPT

Use combination of sudo command and grep command to just find out if port 80 was opened or not:
sudo sh -c 'iptables -L -n -v | grep :80'

Step 4 – Turn on Nginx server

Type the following systemctl command to enable Nginx at boot time:
$ sudo systemctl enable nginx
Start your Nginx webserver:
$ sudo systemctl start nginx
Verify it:
$ systemctl status nginx
Turn On Check Nginx Web Server Service

Is port 80 open?

Run the following netstat command or ss command:
$ sudo netstat -tulpn | grep :80
$ sudo ss -tulpn | grep :80

Is port 80 open on SLES

How to manage the Nginx Web server/service process

Stop Nginx web server:
$ sudo systemctl stop nginx
Start the web server:
$ sudo systemctl start nginx
Restart the service again:
$ sudo systemctl restart nginx
Reload the Ngnix after making configuration changes:
$ sudo systemctl reload nginx

Step 5 – Test Nginx server

Find out your SLES ip address using the ip command:
$ ip a s
$ ip a s eth0

Sample outputs:

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 52:54:00:8a:3c:88 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.43/24 brd 192.168.122.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::5054:ff:fe8a:3c88/64 scope link 
       valid_lft forever preferred_lft forever

Note down your server’s IP address 192.168.122.43. Fire a web browser and type:
http://serve_IP
http://your-domain
http://192.168.122.43


Another option is to run the curl command:
$ curl -I 192.168.122.43
Sample outputs:

HTTP/1.1 200 OK
Server: nginx/1.12.2
Date: Sat, 03 Feb 2018 19:18:53 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 17 Oct 2017 13:30:50 GMT
Connection: keep-alive
ETag: "59e6060a-264"
Accept-Ranges: bytes

Step 6: Finding info about Nginx config files on SLES

Now you have Nginx up and running. It is time to customize it.

Actual path to store your website content

  • /usr/share/nginx/html : You need to store all of your HTML/CSS/js/images files here.

You can upload your files using the scp command or cp command:
$ sudo cp /home/vivek/mysite-files/*.html /usr/share/nginx/html
$ scp ~/projects/cyberciti.biz/static/*.html vivek@192.168.122.43:/usr/share/nginx/html

Server configuration files for SLES

  • /etc/nginx/ : The default nginx config directory
  • /etc/nginx/nginx.conf : The main nginx configuration file
  • /etc/nginx/conf.d/default.conf : The default nginx config file for virtual host

Again use a text editor to edit files:
$ sudo vi /etc/nginx/nginx.conf

Nginx server logs on SLES

  • /var/log/nginx/access.log : All users visitors stored here.
  • /var/log/nginx/error.log : All server errors stored here.

Use tail command or grep command or cat command to view log files:
$ sudo tail -f /var/log/nginx/access.log
$ sudo grep 'foo' /var/log/nginx/error.log

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.

Share this on (or read 2 comments/add one below):

Notable Replies

  1. Chimu says:

    Can I use all commands on OpenSUSE? I do not have SUSE to play with.

  2. nginx is in OpenSUSE repo. No need to configure repo. All you have to do is:

    sudo zypper install nginx
    

    Please note that config file is located at:

    vi /etc/nginx/nginx.conf
    

    The default document root is at /srv/www/htdocs/

    cd /srv/www/htdocs/
    

    You need to upload/copy your html/css/js/image in /srv/www/htdocs/ directory. For example:

    echo 'This is a test page on OpenSUSE running nginx' > /srv/www/htdocs/index.html
    

    Most of the steps are same line:

    systemctl status nginx
    systemctl stop nginx
    systemctl start nginx
    systemctl restart nginx
    

Continue the discussion www.nixcraft.com

Participants