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


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


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


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 have 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.

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 the firewall.

Press Alt-N and Alt-F to save and finish the firewall settings on SLES. Once returned to the shell prompt, list all iptables rules on SLES.

$ sudo iptables -S

Use the 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 web server:


$ sudo systemctl start nginx


Verify it:

$ systemctl status nginx


Is port 80 open?

Run the following netstat command or ss command:

$ sudo netstat -tulpn | grep :80
$ sudo ss -tulpn | grep :80


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


Note down your server’s IP address "ip". Fire a web browser and type:

http://serve_IP
http://your-domain
http://ip address


Another option is to run the curl command:

$ curl -I ip

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/username/mysite-files/*.html /usr/share/nginx/html
$ scp ~/projects/url/static/*.html username@ip:/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 the 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

 

Was this answer helpful? 1 Users Found This Useful (1 Votes)