Friday, July 20, 2018

Learn Nginx installation on windows and Linux

Nginx is a popular opensource web server just like apache server. This will be used in the most popular websites to generate static HTML content.

Nginx Supports following features

  • SSL support
  • Load Balancing
  • Http Caching
  • Static files can be hosted
  • Http authentication
  • Rewrite support for redirection
  • Integrated Proxy and reverse proxy
In this blog, We will go through Nginx installation on Windows, Linux, and Ubuntu

Install on windows 

First please download latest from nginx-1.15.1.zip  , and extract it, place in C folder like c:\nginx-1.15.1 You can set environment variables if required to run nginx command from anywhere To check nginx installation using nginx -v command
C:\\nginx-1.15.1>nginx -v
nginx version: nginx/1.15.1

Nginx Command options

Options Description
-? or -h display documentation of help command
-v Display Version of nginx server
-t Test and display configuration information
-T Test and dump configuration information
-s Signal Sent a signal to nginx process, signals are quit, stop, reopen, reload
-c CustomFileName Default configuration file is conf/nginx.conf. you can add customize custom configuration file to read

Start/Stop server in windows 

nginx -s stop - stopping the server
nginx -s quit - graceful stopping the server
nginx -s reload - reloading the configuration without restart server

 List out Master and child process


c:\nginx-1.15.1>tasklist /fi "imagename eq nginx.exe"
Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
nginx.exe                    14288 Console                    1      6,008 K
nginx.exe                     5032 Console                    1      6,020 K
Log Location in windows are C:\nginx-1.15.1\logs.
access.log - each request logs to server have a entry in access.log
error.log - if any error comes, you can check  error logs

Install web server on Linux operation system

 It is very simple process install using prebuilt packages on Linux os, using yum command, first install epel package and update it using below command

sudo yum install epel-release
sudo yum update
Using Debian based packages
sudo apt-get install nginx
sudo apt-get update
How to get Error logs nginx logs are placed under /var/log/nginx
tail -f /var/log/nginx/error.log

Display nginx version information

C:\nginx-1.15.1>nginx -v
nginx version: nginx/1.15.1

How to change default port Default port is 80. 

To change this to a different port, please modify nginx configuration
vi /etc/nginx/conf.d/default.conf
listen       81;
server_name  localhost;
vi /etc/sysconfig/iptables 
-A INPUT -m state --state NEW -m tcp -p tcp --dport 81 -j ACCEPT
And add this port to iptables configuration to allow this port
 vi /etc/sysconfig/iptables 
-A INPUT -m state --state NEW -m tcp -p tcp --dport 81 -j ACCEPT
Now restart Nginx and iptables to reload these changes.

sudo service iptables restart;
sudo service nginx restart
Web server started with listening at 81 port.

setup configure nginx windows and linux
Now you are able to access web server http://localhost:81


EmoticonEmoticon

Note: Only a member of this blog may post a comment.