Webserver on Linux running in Raspberry PI | NGINX

 NGINX WebServer on Linux on Raspberry PI 


NGINX is web server, reverse proxy server, a mail proxy server, and a generic TCP/UDP proxy server

https://nginx.org/en/


Documentation of NGINX 

https://nginx.org/en/docs/install.html


Commercial version of NGINX is available at ...

https://www.nginx.com/

    

Installation of Nginx Web Server

Installation in Raspberry PI OS   

sudo apt install nginx

Checking version of nginx Server 

$  nginx -v




First test 
As soon as we will install nginx, it is almost ready to work. 
Open browser in different computer and enter either IP address of RSP or hostname in web browser.
you should able to view default webpage.


default web page


Now, as our web browser is running.
It means Nginx webserver is installed and running successfully. 

Now, we should review configuration files available ..

Nginx Configuration

Nginx need to be configured. Configuration step involved setting of location of web-pages, port number etc. following are the configuration files ...

1. /etc/nginx/nginx.conf 

2. /etc/nginx/sites-available/default




Nginx configuration files

Following are the configuration files ...

nginx.conf
location: /etc/nginx/nginx.conf 

This file has three sections... 
events {}
http {}
mail {}
Each section has setting which is related to section name. 

default
location: /etc/nginx/sites-available/default

“default” file in “sites-available” directory has all setting like where html pages will be stored, site name etc. Exact file path ...

/etc/nginx/sites-available/default

Refer server section in default file 

server {

...

root /var/www/html;

       ...

}


Adding new website 

Just add webpage at following locatiion 

/var/www/html/


Once you able to modify configuration files as per requirement, we need to verity configuration file and restart web server, so that it will rerun with all configured settings. 

Testing the configuration files

If any change is made, verify configuration file

pi@raspberrypi:~ $ sudo nginx -t





Verify service 

pi@raspberrypi:~ $ sudo service nginx configtest 
[ ok ] Testing nginx configuration:.


Restarting nginx service 

pi@raspberrypi:~ $ sudo service nginx restart 

Note - if you want to see whether nginx process is running in Linux, try "ps" command as shown in next section. 

Addition Verification 

Nginx Process and Service 


Verify if nginx process is running 
$ ps -ef | grep nginx



we have nginx process is running from /usr/sbin/nginx. worker process are also running. 



Verify if nginx service is running 

$ service --status-all | grep nginx 
 [ + ]  nginx                                  

Nginx listening port

Where nginx is listening 
Use Netstat command tlpn and grep nginx 

$ sudo netstat -tlpn | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      2681/nginx: master  
tcp6       0      0 :::80                   :::*                    LISTEN      2681/nginx: master  

Testing webserver

We have to find out hostname or IP address of Linux OS. or host where webserver is running. 

To find hostname  just run this command ...
hostname




To know ip address run following command ...

hostname -I



Note - ifconfig command can also be used. 


Other web-servers 

Apache HTTP Server https://httpd.apache.org/

Monkey Server http://monkey-project.com/

About EmbeddedCraft

EmbeddedCraft is the information portal for Embedded System and IOT. We are running Website, Blog, YouTube Channel. Stay in touch and many new informative articles are going to publish.

Visit us at …
Our Website: http://embeddedcraft.org/

Embeddedcraft blog
 
 YouTube Channel


 Reddit  
 Twitter   
   Linkedin 





Comments

Popular posts from this blog

Uboot MMC Commands - View content of directory from uboot

Getting Started Raspberry Pi -1 : Installing Raspberry PI OS