Ошибка job for nginx service failed

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 save and exit the file by pressing on your keyboard:

Ctrl + S
Ctrl + X

You may still be prompted to press Y on your keyboard to save your changes.

Finally, confirm that your configuration is correct and restart the Nginx server:

sudo nginx -t
sudo systemctl restart nginx

You can now navigate to localhost:nginx-port (localhost:85) on your browser to confirm the changes.

Displaying the default Nginx start page

If you want the default Nginx start page to show when you navigate to localhost:nginx-port (localhost:85) on your browser, then follow these steps:

Examine the directory /var/www/html/ which is the default root directory for both Apache and Nginx by listing its contents:

cd ~
ls /var/www/html/

You will 2 files listed in the directory:

index.html                # Apache default start page
index.nginx-debian.html   # Nginx default start page

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

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

Change the order of the index files in the root directory from this:

root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

to this (putting the default Nginx start page — index.nginx-debian.html in the 2nd position immediately after index):

root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.nginx-debian.html index.html index.htm;

Then save and exit the file by pressing on your keyboard:

Ctrl + S
Ctrl + X

You may still be prompted to press Y on your keyboard to save your changes.

Finally, confirm that your configuration is correct and restart the Nginx server:

sudo nginx -t
sudo systemctl restart nginx

You can now navigate to localhost:nginx-port (localhost:85) on your browser to confirm the changes.

In this guide, we will cover how to troubleshoot and fix the Nginx Service Job Error, which is commonly encountered when the Nginx service fails to start or restart. The error message usually looks like this:

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

Follow the steps provided in this guide to resolve the issue and ensure the smooth functioning of your Nginx service.

Table of Contents

  • Step 1: Check Status and Error Logs
  • Step 2: Identify and Fix Configuration Errors
  • Step 3: Resolve Port Conflicts
  • Step 4: Check File Permissions
  • Step 5: Restart the Nginx Service
  • FAQ

Step 1: Check Status and Error Logs

The first step in troubleshooting the error is to check the status of the Nginx service and review the error logs. Run the following command to check the status:

sudo systemctl status nginx

To access the error logs, use the following command:

sudo tail -n 20 /var/log/nginx/error.log

This command will display the last 20 lines of the error log. Review the logs to identify any potential issues.

Step 2: Identify and Fix Configuration Errors

In many cases, the Nginx Service Job Error is caused by configuration errors. To check for syntax errors in your configuration files, run the following command:

sudo nginx -t

If there are any errors, the output will indicate the problematic files and lines. Fix the errors in the configuration files and re-run the command to ensure there are no remaining issues.

Step 3: Resolve Port Conflicts

Another common cause of the error is port conflicts. If another service is using the same port as Nginx, it will prevent Nginx from starting. To identify which process is using the conflicting port, use the following command (replace 80 with the port your Nginx is using):

sudo lsof -i :80

If there is a conflicting process, either stop the process or change its port to resolve the conflict.

Step 4: Check File Permissions

Incorrect file permissions can also cause the Nginx Service Job Error. Ensure that the Nginx user has the necessary permissions to access the configuration files, directories, and resources.

For example, to change the ownership of the Nginx configuration directory, use the following command:

sudo chown -R www-data:www-data /etc/nginx

Replace www-data with the appropriate user and group for your system.

Step 5: Restart the Nginx Service

After addressing the issues identified in the previous steps, attempt to restart the Nginx service using the following command:

sudo systemctl restart nginx

If the service starts successfully, the error has been resolved. If the issue persists, review the error logs and configuration files again to identify any remaining issues.

FAQ

Q1: What is the default location of the Nginx error log?

The default location of the Nginx error log is /var/log/nginx/error.log. However, this location can be changed in the Nginx configuration file.

Q2: How do I change the Nginx port number?

To change the Nginx port number, edit the Nginx configuration file (usually located at /etc/nginx/sites-enabled/default). Locate the listen directive and update the port number. Save the changes and restart Nginx to apply the new configuration.

Q3: Can I use both Apache and Nginx on the same server?

Yes, it is possible to use both Apache and Nginx on the same server. However, you will need to configure them to use different ports to avoid port conflicts.

Q4: How do I check the Nginx version?

To check the Nginx version, run the following command:

nginx -v

Q5: How do I enable Nginx to start automatically upon system boot?

To enable Nginx to start automatically upon system boot, use the following command:

sudo systemctl enable nginx
  • Nginx Official Documentation
  • Nginx Configuration Guide

I have a digitalocean droplet with Ubuntu 16.04 running on it. I am serving mostly static sites from it with Nginx, but it suddenly stopped working.

(As you might understand from this intro, I am quite the beginner at all of this.)

I’ve tried to restart nginx:

$ sudo service nginx restart
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.

systemctl status nginx.service:

$ systemctl status nginx.service
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Thu 2019-04-25 12:31:46 UTC; 55s ago
     Docs: man:nginx(8)
  Process: 8232 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
  Process: 8221 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)

journalctl -xe

    $ sudo journalctl -u nginx
    - Logs begin at Thu 2019-03-21 01:07:26 UTC, end at Thu 2019-04-25 12:54:26 UTC. --
Apr 25 10:33:29 ubuntu-s-michaelsimsoe systemd[1]: Stopping A high performance web server and a reverse proxy server...
Apr 25 10:33:29 ubuntu-s-michaelsimsoe systemd[1]: Stopped A high performance web server and a reverse proxy server.
-- Reboot --
Apr 25 10:34:16 ubuntu-s-michaelsimsoe systemd[1]: Starting A high performance web server and a reverse proxy server...
Apr 25 10:34:17 ubuntu-s-michaelsimsoe nginx[1242]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 25 10:34:17 ubuntu-s-michaelsimsoe nginx[1242]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 25 10:34:18 ubuntu-s-michaelsimsoe nginx[1242]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 25 10:34:18 ubuntu-s-michaelsimsoe nginx[1242]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 25 10:34:18 ubuntu-s-michaelsimsoe nginx[1242]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 25 10:34:18 ubuntu-s-michaelsimsoe nginx[1242]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 25 10:34:19 ubuntu-s-michaelsimsoe nginx[1242]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 25 10:34:19 ubuntu-s-michaelsimsoe nginx[1242]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 25 10:34:19 ubuntu-s-michaelsimsoe nginx[1242]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 25 10:34:19 ubuntu-s-michaelsimsoe nginx[1242]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 25 10:34:20 ubuntu-s-michaelsimsoe nginx[1242]: nginx: [emerg] still could not bind()
Apr 25 10:34:20 ubuntu-s-michaelsimsoe systemd[1]: nginx.service: Control process exited, code=exited status=1
Apr 25 10:34:20 ubuntu-s-michaelsimsoe systemd[1]: nginx.service: Failed with result 'exit-code'.
Apr 25 10:34:20 ubuntu-s-michaelsimsoe systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Apr 25 12:08:48 ubuntu-s-michaelsimsoe systemd[1]: Starting A high performance web server and a reverse proxy server...
Apr 25 12:08:48 ubuntu-s-michaelsimsoe nginx[21464]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 25 12:08:48 ubuntu-s-michaelsimsoe nginx[21464]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 25 12:08:49 ubuntu-s-michaelsimsoe nginx[21464]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 25 12:08:49 ubuntu-s-michaelsimsoe nginx[21464]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 25 12:08:49 ubuntu-s-michaelsimsoe nginx[21464]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 25 12:08:49 ubuntu-s-michaelsimsoe nginx[21464]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 25 12:08:50 ubuntu-s-michaelsimsoe nginx[21464]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 25 12:08:50 ubuntu-s-michaelsimsoe nginx[21464]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 25 12:08:50 ubuntu-s-michaelsimsoe nginx[21464]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 25 12:08:50 ubuntu-s-michaelsimsoe nginx[21464]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 25 12:08:51 ubuntu-s-michaelsimsoe nginx[21464]: nginx: [emerg] still could not bind()
Apr 25 12:08:51 ubuntu-s-michaelsimsoe systemd[1]: nginx.service: Control process exited, code=exited status=1
Apr 25 12:08:51 ubuntu-s-michaelsimsoe systemd[1]: nginx.service: Failed with result 'exit-code'.
Apr 25 12:08:51 ubuntu-s-michaelsimsoe systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Apr 25 12:10:24 ubuntu-s-michaelsimsoe systemd[1]: Starting A high performance web server and a reverse proxy server...
Apr 25 12:10:25 ubuntu-s-michaelsimsoe nginx[25175]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 25 12:10:25 ubuntu-s-michaelsimsoe nginx[25175]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 25 12:10:25 ubuntu-s-michaelsimsoe nginx[25175]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 25 12:10:25 ubuntu-s-michaelsimsoe nginx[25175]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 25 12:10:26 ubuntu-s-michaelsimsoe nginx[25175]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 25 12:10:26 ubuntu-s-michaelsimsoe nginx[25175]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 25 12:10:26 ubuntu-s-michaelsimsoe nginx[25175]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 25 12:10:26 ubuntu-s-michaelsimsoe nginx[25175]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 25 12:10:27 ubuntu-s-michaelsimsoe nginx[25175]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 25 12:10:27 ubuntu-s-michaelsimsoe nginx[25175]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 25 12:10:27 ubuntu-s-michaelsimsoe nginx[25175]: nginx: [emerg] still could not bind()
Apr 25 12:10:27 ubuntu-s-michaelsimsoe systemd[1]: nginx.service: Control process exited, code=exited status=1
Apr 25 12:10:27 ubuntu-s-michaelsimsoe systemd[1]: nginx.service: Failed with result 'exit-code'.
Apr 25 12:10:27 ubuntu-s-michaelsimsoe systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Apr 25 12:12:59 ubuntu-s-michaelsimsoe systemd[1]: Starting A high performance web server and a reverse proxy server...
Apr 25 12:12:59 ubuntu-s-michaelsimsoe nginx[30965]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 25 12:12:59 ubuntu-s-michaelsimsoe nginx[30965]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 25 12:12:59 ubuntu-s-michaelsimsoe nginx[30965]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 25 12:12:59 ubuntu-s-michaelsimsoe nginx[30965]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 25 12:13:00 ubuntu-s-michaelsimsoe nginx[30965]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

The following have been done by me before I noticed the errors:
* Changed root password
* Changed password for user michaels
* Changed ownership of website folders (I’m trying to set up webhooks)

Any thoughts on what it might be?

EDIT: some additional information

$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

$ ps -A | nginx
nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)
2019/04/25 13:09:32 [warn] 28351#28351: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1
2019/04/25 13:09:32 [emerg] 28351#28351: BIO_new_file("/etc/letsencrypt/live/huske.michaelsimsoe.no/fullchain.pem") failed (SSL: error:0200100D:system library:fopen:Permission denied:fopen('/etc/letsencrypt/live/huske.michaelsimsoe.no/fullchain.pem','r') error:2006D002:BIO routines:BIO_new_file:system lib)

Before I installed nginx I had som pages served by Apache. I can reach these still.

Nginx 1.12.0, Linux RH 7.2
Установил, сделал конфиг — проверка конфига выдает что все ок:

nginx: the configuration file /etc/nginx/conf.d/ev1.conf syntax is ok
nginx: configuration file /etc/nginx/conf.d/ev1.conf test is successful

Запускаю, выдает ошибку:

systemctl start nginx.service
Job for nginx.service failed because the control process exited with error code. See «systemctl status nginx.service» and «journalctl -xe» for details.

смотрю логи:

Starting nginx — high performance web server…
nginx: [emerg] «events» directive is not allowed here in /etc/nginx/conf.d/ev1.conf:1
nginx: configuration file /etc/nginx/nginx.conf test failed
nginx.service: control process exited, code=exited status=1

Запускаю со стандартным конфигом — запускается без ошибок. Возвращаю конфиг — снова ошибки. Как понять что не так с конфигом (тест конфига проходит нормально).

So you’ve got two things which are in conflict and have led it seems to the nginx binaries going away somehow: Xenial repository version, and the NGINX PPA. As the maintainer of both, allow me to explain the conflict.

In Xenial, we released 1.10.0 just after release as an update. This update pushed us to a ‘stable’ branch but didn’t have dynamically-loadable modules built and made available. This was due to time but also build conflicts that arose during tests. We eventually got dynamic module support working, in Zesty.

In the PPA, we’ve always cloned directly from Debian. That means, we always had Debian’s ‘dynamic module’ support, which conflicted with the Xenial packages and resulted in some installation and upgrade conflicts.


There’s a small conflict here — you can’t mix-and-match nginx-core (which is the default flavor installed for the nginx package in Ubuntu) and the PPAs, as it sometimes makes things disappearify. The problem here, then, is we need to remove the existing Ubuntu package and then install from the PPA only.

To resolve this, you’ll first need to back up your nginx configurations you want to keep for your sites. That is, make a copy of your /etc/nginx/sites-available/ directory somewhere else (even in your user’s home directory is fine, we just need a copy of the site configurations). As well, we’ll need a backup of your website data, so copy that somewhere else as well (NOT in the standard docroot, so it doesn’t get messed up).

Once you make the copy, you’ll have to remove the existing nginx packages. This can be done with the following command:

sudo apt-get remove nginx nginx-common nginx-doc nginx-core nginx-full nginx-extras nginx-light

Once that is complete, run sudo apt-get update again just to make sure we have the most up to date version numberings.

Then, install nginx from the PPA — sudo apt-get install nginx nginx-full nginx-common should do this.

You should no longer be getting failed to start errors. Make sure your site configurations are still in place, and didn’t get overwritten. If they did, restore from the backups we took earlier of the site config and the site data. Otherwise, you’re all set.

Понравилась статья? Поделить с друзьями:
  • Ошибка lci на стиральной машинке самсунг
  • Ошибка jenkins при запуске 1с
  • Ошибка lc1 в стиральной машине samsung что делать
  • Ошибка javaw exe в minecraft
  • Ошибка lc1 в стиральной машине samsung как устранить ошибку