How to use Nginx and Apache server together. | check to know more | How to use Nginx as reverse proxy on Ubuntu machine.

For hosting the website we use in server side some web services. That services provides us some more important tools to configure and manage. In between some service the Nginx and Apache is the most used web-services and well known services. In  a simple to host a website we require a some service from server. In machine we can configure both Apache and Nginx web server but in normal way we can configure only one. But think if you have multiple website and you want to host in same server. In that case we can configure the both Nginx and Apache to host your both website and also more then two website in a same  a machine. Well in this blog i am going to show you how to install and configure both Nginx and Apache services in a same machine. I will use an Ubuntu machine to demonstrate.


What is Apache?

cloudpradeep


  • Apache service is a web-server application that helps to deliver web-services through the internet.

  • It is a open-source and cross platform service. It is developed and maintained by an open source community.

  • It is most commonly use on Unix-like system.

  • This software is available for Unix, Linux, Os X, free BSB , windows based operating system.

What is Nginx ?

How to use Nginx and Apache server together


  • Nginx is a web-server application that helps to deliver web-service through the internet.
  • it is a open-source and cross platform based service. It is developed and maintained by open source community.
  • It is is used unlike every operating system.

  • It is a latest way to deliver web service because is comes after the traditional Apache web server.

How to configure both Apache and Nginx together?

In ubuntu or in Debian kind of machine the apche web-serice is known as apache2 so to install the apache in our debian machine we have to use each and every time apache2 and for other operating system it is simple apache.

To install the Apache2 :-

  sudo apt install apache2 -y
 
  Now update the files using this command :- 
  
  sudo apt update 
  
  After installation will complete then configure the listinging port 80 to 8080. By using this command.
  
  sudo vim /etc/apache2/port.conf
 
 Now it will open a configuration terminal then find the line named as Listen 80 and just add 8080 number and now save and exit form the vim text editor.
 
 Now start and enable the service by using this command bellow. For enable command is used to start the service after the system reboot.
 
  systemctl start apache2
  systemctl enable apache2
 
Now the apache configuration is done now. It's time to start the installation and confuguration of Nginx web server. 

To install the nginx use this command :- 

sudo apt install nginx -y
Once the installation will complete then create an proxy configuration :- 

sudo vim /etc/nginx/conf.d/proxy.conf
Now it will opened a new text file then simple type or paste this :-

server {
    listen 80;
    server_name test.example.com;
    location ~ \.php$ {
        proxy_pass http:// [ your ip address ]:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

note- We are just configuring the nginx to listion the port 80 by using above commands.

Now installation and configuratioin is done now it's time to start the service. To start the service use this commands.

systemctl start nginx
systemctl enable nginx
Now create a html file or you can use your existing html file for this process. But should be in this path given bellow. 

sudo vim /var/www/html/sahoo.html
in that html file your content should be like in this format. It is only applicable only when you are creating a new html file. If you have already any html file then it doesn't require.

<html>
<body>
<h1>Apache</h1>
<p> this is my NGINX site </p>
</body>
</html>

Now save and close. If you have your own html file then just copy the file in to /var/www/html/ directory 

Now open your browser and search http://your ip :8080/sahoo.html


That's all about how to install and configure the Nginx and Apache on a ubuntu server.

No comments