Configure UI Layer on apache2

What is Apache2 ?

Apache is the most popular web server on the internet.It is used to serve more than half of all active websites.So lets configure it for our local development.

Installing Apache2 or httpd on Ubuntu or Debian

Open Terminal and run the following commands
    $ sudo apt-get update
    $ sudo apt-get install apache2

Assuming your workspace is in /home/user/workspace/UI directory
    $ cd /var/www
    $ sudo ln -s /home/user/workspace/UI UI
The second command creates a symbolic link to your repository.

Now, we will configure our apache server to serve static contents so that 
we can run our code locally.

Configure Apache2

$ cd /etc/apache2/conf-available

Create a file fqdn.conf inside conf-available directory containing following text:
ServerName localhost

and then again create a symbolic link to fqdn.conf file
$   cd /etc/apache2/conf-enabled
$   sudo ln -s ../conf-available/fqdn.conf fqdn.conf

Add UI workspace files and ProxyPass settings to apache2 server 
Before that let us take a backup of our setting file 000-default.conf.
Backup file name is 000-default.conf.bak

$   cd /etc/apache2/sites-available
$   sudo cp 000-default.conf 000-default.conf.bak

Now modify file 000-default.conf as the following:

Change DocumentRoot to:
DocumentRoot /var/www/UI

Add the following lines towards the end of the file, just before closing </VirtualHost> tag

        ProxyRequests Off
        <Proxy *>
                Order deny,allow
                Allow from all
        </Proxy>

        ProxyPass /api http://IPAddress
        ProxyPassReverse / http://IPAddress

        <Location />
                Order allow,deny
                Allow from all
        </Location>     

After making above changes,
Enable proxy module and restart apache2 server.


    $   sudo a2enmod proxy
    $   sudo a2enmod proxy_http
    $   sudo service apache2 restart
Open up your favorite browser and type localhost
This is all about configuring UI on your local Machine for development.
The same UI can be configured and run on node server.
 


Comparison between Apache and Nginx

Both Apache and Nginx are popular and are used in wide variety of applications .
Most of the time it become an important decision to choose between Nginx and Apache for their application .Apache is more popular than Nginx because it covers more use cases and it has been around much longer, hence more people know about it .

Say for example :
With Apache, you just need to run/maintain/configure a single software that handles everything you might need like static files (css/js/images), PHP , Python, etc. It supports a lot of configuration options that cater to various use cases but is a little resource heavy (i.e. uses more CPU/RAM).

Nginx, on the other hand, just serves static files and also allows you to load balance (transfer your incoming request to one among a set of servers, depending on load), and some other stuff too. But it is much lighter on resources. Moreover, you would have to use something else to handle your dynamic content (PHP (programming language)/Python). Thus, you would have to run/maintain/configure multiple pieces of software.

Apache makes copies (process forks) of itself for every request, be it PHP or a css file. Each running version eats up more RAM. So you have a very low limit on the number of things it can do at one time.

Nginx on the other hand uses a fixed amount of RAM because it is event driven. So you can use your RAM for other things, like PHP

So from my side a piece of advice ,Use Apache if you just want to manage one thing and don’t mind resource usage and use nginx if you have lots of static content or are resource constrained or you like to use “the right tool for the right job”!

Why nginx is good at serving static files?

It’s not any better/worse at serving static files than Apache. However, the big difference is that nginx can serve a lot more users without using up additional resources.

Apache makes copies (process forks) of itself for every request, be it PHP or a css file. Each running version eats up more RAM. So you have a very low limit on the number of things it can do at one time.

Nginx on the other hand uses a fixed amount of RAM because it is event driven. So you can use your RAM for other things, like PHP.

Why nginx + apache?

nginx is configured to serve the static (js, css, img) files. So you have a fixed amount of ram handling all the regular files. No need to use up a fat copy of apache to serve something simple.

apache+mod_php, can just focus on creating dynamic HTML. Which means more effective use of your precious RAM.

For more details please go through these links :

Apache vs nginx – WikiVS
Nginx Vs Apache in AWS – Updated
Web Server Performance Comparison
Nginx overtakes Apache as the server of choice for the top 1000 trafficked sites
Apache vs nginx {performance comparison}
Apache2 vs Nginx for PHP application

I use both on a few projects. Apache for the main web server and nginx as a caching server only sitting in front of Apache.I use Nginx for static content and caching.
Apache remains better for production as it provides an important range of handful plugins.