0

After installing Apache web server some days ago, I just installed Nginx web server on my Ubuntu local machine in order to setup a reverse proxy server. But when I try to start up Nginx server by running the command below in my terminal

systemctl start nginx

I get the error below

Job for nginx.service failed because the control process exited with error code.

See "systemctl status nginx.service" and "journalctl -xe" for details.

I have tried to check the status of Nginx service by running the command below

 systemctl status nginx.service

but I get the response below

● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: en
   Active: failed (Result: exit-code) since Thu 2019-10-10 12:39:18 WAT; 16s ago
     Docs: man:nginx(8)
  Process: 6501 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code
  Process: 6500 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process

I have tried to fix the issue, but I seem not to be make any headway.

I need some assistance.

0

The cause of the issue is this, I already had Apache web server installed and actively listening on port 80 on my local machine.

Apache and Nginx are the two major open-source high-performance web servers capable of handling diverse workloads to satisfy the needs of modern web demands. However, Apache serves primarily as a HTTP server whereas Nginx is a high-performance asynchronous web server and reverse proxy server.

The inability of Nginx to start was because Apache was already listening on port 80 as its default port, which is also the default port for Nginx.

One quick workaround would be to stop Apache server by running the command below

systemctl stop apache2
systemctl status apache2

And then starting up Nginx server by running the command below

systemctl stop nginx
systemctl status nginx

However, this same issue will arise again when we try to start Apache server again, since they both use port 80 as their default port.

Here's how I fixed it

Run the command below to open the default configuration file of Nginx in Nano editor

sudo nano /etc/nginx/sites-available/default

When the file opens in Nano editor, scroll down and change the default server port to any port of your choice. For me, I chose to change it to port 85

# Default server configuration
#
server {
       listen 85 default_server;
       listen [::]:85 default_server;

Also, scroll down and change the virtual host port to any port of your choice. For me, I also chose to change it to port 85

# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
# server {
#        listen 85;
#        listen [::]:85;

Then exit the file by pressing on your keyboard

Ctrl + X

And then Press Y on your keyboard to save the changes.

That's all.

I hope this helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.