Nginx is free, open source HTTP server and reverse proxy. It is also a mail proxy server for IMAP/POP3. Nginx is high performance web server with a rich set of features, simple configuration style and low memory usage.
Using Nginx as a reverse proxy is a great idea for several reasons. Firstly it handles static content very well. It is able to handle the requests and serve static content much faster in our tests and this has cut our page load time in about half. Both nginx and apache are powerful and effective servers. Apache is known for it's power and Nginx is known for it's speed.
Common uses for a reverse proxy server include:
Load Balancing - A reverse proxy server sitting in front of your backend servers and distributing client requests across a group of servers in a manner that maximises speed and capacity utilisation whilst ensuring no single server is overloaded, which can degrade performance. If a server goes down, the load balancer redirects traffic to the remaining online servers.
Web Acceleration - Reverse proxies can compress inbound and outbound data, as well as cache commonly requested content, both of which speed up the flow of traffic between clients and servers.
Security and Anonymity - By intercepting requests headed for your backend servers, a reverse proxy server protects their identities and acts as an additional defense against security attacks.
In this tutorial, we will install and configure the Nginx web server as reverse proxy for Apache on Ubuntu-14.04. Apache will run on port 8080, then we will configure Nginx run on port 80 to receive a request from user, the request will then be forwarded to the apache server that is running on port 8080.
A server running Ubuntu-14.04.
A static IP Address for your server.
A non-root user account with sudo privilege set up on your server.
Let's start by making sure that your Ubuntu server is fully up to date.
You can update your server by running the following command:
sudo apt-get updatesudo apt-get upgrade
Firstly, you will need to install and configure Nginx which will serve the front end of your site.
Run the following command to install Nginx on terminal:
sudo apt-get install nginx
Once Nginx is installed, you will need to setup Nginx as reverse proxy.
You can do this by creating new virtual host file:
sudo nano /etc/nginx/sites-available/proxyhost
Add the following content:
index index.php index.html index.htm;
In the above file, The root directive specify the path of default document root directory. try_files attempts to serve whatever page the visitor requests. If nginx is unable, then the file is passed to the proxy.
proxy_pass defines the address of the proxied server. localtion directive block denies access to .htaccess file.
You can check Nginx configuration syntax by running the following command:
sudo nginx -t
You should see the following output if everything is ok:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Now, activate the virtual host by running the following command:
Next, you will need to install Apache for the backend. You can install Apache by running the following command:
sudo apt-get install apache2
Next, you will need to configure apache to take over the backend. Since Nginx is listening to 80 and we told it to pass the proxy to 8080 which should be where Apache is listening to receive a request. Let's tell Apache to listen to 8080 and leave 80 for Nginx.
Open up the apache ports file to start setting apache on the correct port:
Truth be told, it’s difficult for a web application that doesn’t have some kind of identification, even if you don’t see it as a security measure in and of itself. The Internet is a kind of lawless land, and even on free services like Google’s, authentication ensures that abuses will...
Although data persistence is almost always a fundamental element of applications, Node.js has no native integration with databases. Everything is delegated to third-party libraries to be included manually, in addition to the standard APIs. Although MongoDB and other non-relational databases are the most common choice with Node because if you...