How to use Apache webserver and Nginx webserver in single instance

To use Apache webserver and NGINX webserver in single instance   

Apache webserver is a free and open-source, cross-platform web server software. It supports a variety of features as a set of compiled modules and also contains core functionality. Nginx is a webserver that is also used as reverse proxy, load balancer and HTTP cache. This tutorial covers the configuration procedure of Apache webserver and NGINX webserver in single instance. 

 

Configuration procedure

To proceed with the configuration procedure, install the httpd service by running the following command. 

[root@linuxhelp ~]# yum install httpd -y
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: centos.excellmedia.net
 * extras: centos.excellmedia.net
 * updates: centos.excellmedia.net
.
.
Verifying  : httpd-tools-2.2.15-60.el6.centos.4.x86_64                    4/4
Updated:
  httpd.x86_64 0:2.2.15-60.el6.centos.5                                         

Dependency Updated:
  httpd-tools.x86_64 0:2.2.15-60.el6.centos.5                                   

Run the following commands to start and enable your Apache service. 

[root@linuxhelp ~]# service httpd start
Starting httpd:
[root@linuxhelp ~]# chkconfig httpd on

Go to httpd.conf configuration file and provide your domain name as your server name. Save the changes and restart your apache service. 

[root@linuxhelp ~]# vim /etc/httpd/conf/httpd.conf
ServerName ns2.linuxhelp.com:80

Move to Apache root directory and create index.html file. 

[root@linuxhelp ~]# cd /var/www/html/
[root@linuxhelp ~]# vim index.html
Apache service is running

[root@linuxhelp ~]# service httpd restart
Stopping httpd:                                           [  OK  ]
Starting httpd:                                             [  OK  ]

Switch over to the browser and provide the machine's IP or domain name. The screen will show as below. 

apache service

Now install the NGINX service by running the following command. 

[root@linuxhelp ~]# yum install nginx

--> Processing Dependency: nginx-mod-http-perl = 1.10.2-1.el6 for package: nginx-all-modules-1.10.2-1.el6.noarch
--> Processing Dependency: nginx-mod-http-image-filter = 1.10.2-1.el6 for package: nginx-all-modules-1.10.2-1.el6.noarch
--> Processing Dependency: nginx-mod-http-geoip = 1.10.2-1.el6 for package: nginx-all-modules-1.10.2-1.el6.noarch
---> Package nginx-filesystem.noarch 0:1.10.2-1.el6 will be installed
--> Running transaction check
.
.
.
nginx-mod-http-perl.x86_64 0:1.10.2-1.el6                                     
  nginx-mod-http-xslt-filter.x86_64 0:1.10.2-1.el6                              
  nginx-mod-mail.x86_64 0:1.10.2-1.el6                                          
  nginx-mod-stream.x86_64 0:1.10.2-1.el6                                       
Complete!

Try starting the NGINX service by running the following command. 

[root@linuxhelp ~]# service nginx start
Starting nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
                                                           [FAILED]

It has failed because the Apache service is using port 80. Now move to your NGINX configuration file and create a configuration file named default.conf using vim editor. 

[root@linuxhelp ~]# vim /etc/nginx/conf.d/default.conf

Change the listen port to 8085
port

Save the changes in the file and try to restart the NGINX service

[root@linuxhelp ~]# service nginx start
Starting nginx:                                            [  OK  ]
[root@linuxhelp ~]# chkconfig nginx on

Go to its root directory and list the files in the directory. Create a file named index.html using vim editor. 

[root@linuxhelp ~]# cd /usr/share/nginx/
[root@linuxhelp nginx]# ls -l
total 8
drwxr-xr-x 2 root root 4096 Sep  7 10:35 html
drwxr-xr-x 2 root root 4096 Sep  7 10:35 modules
[root@linuxhelp nginx]# cd html/
[root@linuxhelp html]# vim index.html


index

Rename the index.html and creating new index.html file

[root@linuxhelp ~]# vim index.html
Nginx service is working

Restart your nginx service

Now switch over to the browser and provide the following URL http://your machine's IP:8085. The Nginx service is running successfully. 

nginxTh

The configuration procedure of Apache and NGINX webserver in single instances. 


Thank you! for using Linux Help.

You find this tutorial helpful? Share with your friends to keep it alive.
For more help topics browse our website www.linuxhelp.com
Be the first to comment, we value your suggestions. For further queries please comment below.

Tags: Nginx Apache
user image Author :  Ethan