Home EngineerA way to prevent conflict between Nginx and Apache server

A way to prevent conflict between Nginx and Apache server

by Quy Ta
1 minutes read

Following the series of bash commands along with its comments to allow Nginx Server and Apache Server to be able to run along with each other. There are two conflicts we are resolving in this article:

  1. The duplication in port: both of them are listening to the same port 80
  2. The duplication in default HTML page: this doesn’t matter, it depends on the usage of pointing the server to which service or which static HTML pages. For the further demo purpose of my labs, we will not point both services to serve the same directory. In this case: /var/www/html
# install nginx in ubuntu
sudo apt update -y
sudo apt install nginx -y

# create static folder for nginx and the index file
sudo mkdir -p /var/www/nginx/html
sudo chmod 777 -R /var/www/nginx/html
echo "hello world" > /var/www/nginx/html/index.html

# update the default site configuration
sudo nano /etc/nginx/sites-available/default

The following are to be added to the default configuration of the nginx server

listen 8001 default_server;
listen [::]:8001 default_server;

# and
root /var/www/nginx/html;

After that, we can just restart and test for the result

sudo nginx -t
sudo systemctl restart nginx
sudo systemctl status nginx

curl localhost:8001

The results should be returned like this below

Final results of port 8001 and the content of a returned static page

You may also like