Nginx is a lightweight webserver which is more stable and secure, it serves static content 50 times faster than Apache. nginx is a perfect load balancer can able to handle more than 7000 live request per second , In the meantime it consumes only less cpu and memory.
Nginx reverse proxy is very powerful and can be used behind any other webserver ( Apache,IIS etc ).
Here we can see how to install and configure nginx in ubuntu 12.04
» Installing nginx
» Mysql installation
» PHP installation for Nginx
» Nginx configuration and testing
» Nginx Reverse proxy
» SSL enabled
Update ubuntu repositories by giving the below command
krizna@leela:~$ sudo apt-get update
Step 1 » Issue the below command for installing nginx package from repository .
krizna@leela:~$ sudo apt-get install nginx
The above command will install nginx along with dependencies.
Step 2 » After installation , let’s start nginx service.
krizna@leela:~$ sudo /etc/init.d/nginx start
Now open the server IP in your browser (Eg: http://192.168.1.1 ). you can see the Nginx welcome page.
For mysql installation please refer this page Mysql server installation on ubuntu 12.04
Step 3 » Nginx can process PHP files through php-fpm (FastCGI Process Manager) . Issue the below command to install PHP-FPM
krizna@leela:~$ sudo apt-get install php5-fpm php5-mysql php5-xcache
Step 4 » Now we can test nginx server using simple configuration . Follow the steps one by one
krizna@leela:~$ sudo mkdir /usr/share/nginx/www/testkrizna@leela:~$ cd /usr/share/nginx/www/test
and create index.php file and paste the below code and save it
<?php phpinfo(); ?>
Step 5 » Now create a virtual sitekrizna@leela:~$ cd /etc/nginx/sites-available
and create a file called test and paste the below configuration .
server {
listen 8080;
root /usr/share/nginx/www/test;
location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
} The above configuration will listen on port 8080 with the root directory path /usr/share/nginx/www/test where we created the index.php file.
Step 6 » Enable the virtual site by issuing the below commandkrizna@leela:~$ ln -s /etc/nginx/sites-available/test /etc/nginx/sites-enabled/test
Step 7 » Now restart nginx service krizna@leela:~$ sudo /etc/init.d/nginx restart
Now open the server IP with port 8080 in your browser ( Eg: http://192.168.1.1:8080 ) . you can see the php info page like below.
Please refer the diagram and the configuration below
upstream apache {
server 192.168.2.1:80;
}
server {
listen 8080;
location / {
proxy_redirect off;
proxy_pass http://apache;
include proxy_params;
}
}
upstream iis {
server 192.168.2.2:8000;
}
server {
listen 80;
location / {
proxy_redirect off;
proxy_pass http://iis;
include proxy_params;
}
} You can create a another virtual site to test this configuration.
upstream apache {
server 192.168.2.1:80;
}
server {
listen 443;
ssl on;
ssl_certificate /etc/nginx/server.crt;
ssl_certificate_key /etc/nginx/server.key;
location / {
proxy_redirect off;
proxy_pass http://apache;
include proxy_params;
}
} Please note these configurations are only for testing not for live servers .
Visual Studio Code is a popular code editor which is lightweight and cross platform application.…
MySQL workbench is a GUI tool for managing MySQL database system. It is used by…
Android Studio is a popular development software used especially for developing android applications. It is…
Google chrome is a most popular web browser developed by google. It was developed to…
Zoom is a popular video conferencing software. It is commonly used for conducting online meetings,…
TeamViewer is a popular application for desktop sharing and remote control. It is available for…