• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Resolved Can not start nginx (systemd prechecks are failing)

zepho

New Pleskian
Hey together,

a few weeks ago I had to restore a server. We run nginx as reverse proxy and were not able to start nginx the normal way. After:
Code:
systemctl restart nginx.service

Journal-log is complaining about an "argument" concerning the test command.

Code:
● nginx.service - Startup script for nginx service
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled)
   Active: failed (Result: exit-code) since Tue 2016-07-26 02:36:56 CEST; 2min 57s ago
  Process: 2838 ExecStop=/bin/kill -s QUIT $MAINPID (code=exited, status=0/SUCCESS)
  Process: 2842 ExecStartPre=/usr/bin/test $NGINX_ENABLED = yes (code=exited, status=2)
Main PID: 2023 (code=exited, status=0/SUCCESS)

... sub.host.tld test[2842]: /usr/bin/test: missing argument after ‘yes’
... sub.host.tld systemd[1]: nginx.service: control process exited, code=exited status=2
... sub.host.tld systemd[1]: Failed to start Startup script for nginx service.
... sub.host.tld systemd[1]: Unit nginx.service entered failed state.

So I took a look at /lib/systemd/system/nginx.service:

Code:
ExecStartPre=/usr/bin/test $NGINX_ENABLED = "yes"
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx

ExecReload=/usr/bin/test $NGINX_ENABLED = "yes"
ExecReload=/usr/sbin/nginx -t
ExecReload=/bin/kill -s HUP $MAINPID

ExecStop=/bin/kill -s QUIT $MAINPID

Without further testing, it looks to me like $NGINX_ENABLED is not defined.

To get nginx to start I comment it out to:
Code:
#ExecStartPre=/usr/bin/test $NGINX_ENABLED = "yes"
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx

#ExecReload=/usr/bin/test $NGINX_ENABLED = "yes"
ExecReload=/usr/sbin/nginx -t
ExecReload=/bin/kill -s HUP $MAINPID

ExecStop=/bin/kill -s QUIT $MAINPID

With that quirky patch everything worked fine the last weeks. But I am wondering what causes the problem.

"plesk repair" and "plesk sbin nginxmng --enable" already happend.

My specs:
- Debian v8.4
- Plesk v12.5.30_build1205150826.19 os_Debian 8.0
- nginx v1.11.1


What am I missing? Can you help me?
Any suggestions?

Thanks in advance.
 
Seems nginx is disabled.

Try the following:
# plesk sbin nginxmng --enable
 
Okay, I looked myself to find a solution and following worked for me:

Symptom-check:
Code:
# /usr/local/psa/admin/sbin/nginxmng -s
Enabled
# /opt/psa/admin/sbin/nginx_proxy -s
off

Code:
# /opt/psa/admin/sbin/nginx_proxy -h
gave me
Code:
Usage: nginx_proxy { --on | --off } --port-map <mapping> [ --no-httpd-selinux-fix ]
       nginx_proxy --status

        -s, --status    Check whether NGINX is enabled in proxy mode
        -e, --on        Turn on NGINX as reverse proxy to Apache
        -d, --off       Turn off NGINX as reverse proxy and make Apache frontend server

        -m, --port-map <from1:to1,from2:to2,...>
                        Specify Apache ports mapping during enabling or disabling
                        NGINX as reverse proxy.
        -n, --no-httpd-selinux-fix
                        Normally Apache is allowed to bind to a restricted set of ports
                        by SELinux. By default upon making Apache a backend server
                        this utility would allow it to bind to any unprivileged port.
                        This option suppresses such behavior.
                        You can manually allow Apache to use specific ports, e.g. using:
                        # semanage port -a -t http_port_t -p tcp <port>
Warning: this utility expects that all web server configuration files except main
ones have already been updated. Otherwise NGINX and Apache may fail to start.

Im not entirely aware how Plesk is mapping the ports, but I guess following ***could*** work (I did not test):

Code:
# nginx_proxy --on  --port-map <80:7080,443:7081>

Also I recognized that the parameter file /etc/default/nginx was simply empty...

And this caused our problem!

Solution option 1:
Code:
echo "NGINX_ENABLED=yes" > /etc/default/nginx
Solution option 2:
Code:
# /usr/local/psa/admin/sbin/nginxmng -d
# /usr/local/psa/admin/sbin/nginxmng -e
 
Back
Top