nginx does not start automatically, what have I done?

J
  • 16 Feb '23
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20230216/f9e2087a/attachment.htm>
M
  • 16 Feb '23
Hello!

On Thu, Feb 16, 2023 at 02:48:23PM +0800, JK wrote:

>    Hello, it is my first time posting here, and I appreciate the
>    opportunity to share my experience with nginx.
> 
> 
>    Just to give you background, I am using a VPS from Racknerd, and I use
>    CWP (Control Web Panel), which is pretty similar to cPanel.
> 
> 
>    I tried to update the repo and use dnf upgrade -y, and what happened
>    was, after restarting the server, nginx did not start automatically.
> 
> 
>    Here is the log of nginx:
> 
> 
>    ● nginx.service - The nginx HTTP and reverse proxy server
>       Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled;
>    vendor preset: disabled)
>       Active: failed (Result: exit-code) since Wed 2023-02-15 17:29:03
>    EST; 7h ago
>      Process: 779 ExecStartPre=/usr/sbin/nginx -t (code=exited,
>    status=1/FAILURE)
>      Process: 776 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited,
>    status=0/SUCCESS)
>    Feb 15 17:29:02 racknerd-f5**** systemd[1]: Starting The nginx HTTP and
>    reverse proxy server...
>    Feb 15 17:29:02 racknerd-f5**** nginx[779]: nginx: the configuration
>    file /etc/nginx/nginx.conf syntax is ok
>    Feb 15 17:29:03 racknerd-f5**** nginx[779]: nginx: [emerg] bind() to
>    100.xx.xx.xx:80 failed (99: Cannot assign requested address)
>    Feb 15 17:29:03 racknerd-f5**** nginx[779]: nginx: configuration file
>    /etc/nginx/nginx.conf test failed
>    Feb 15 17:29:03 racknerd-f5**** systemd[1]: nginx.service: Control
>    process exited, code=exited status=1
>    Feb 15 17:29:03 racknerd-f5**** systemd[1]: nginx.service: Failed with
>    result 'exit-code'.
>    Feb 15 17:29:03 racknerd-f5**** systemd[1]: Failed to start The nginx
>    HTTP and reverse proxy server.
> 
> 
>    The solution is to manually start nginx after a minute or two.

The error message "bind() to 100.xx.xx.xx:80 failed (99: Cannot 
assign requested address)" suggests the IP address you are trying 
to use is not available when nginx starts.

Possible options to fix this include:

- Make sure nginx systemd service properly depends on the network 
  being available (After=/Wants= network-online.target is usually 
  good enough, though you may need to also enable proper wait 
  service, see [1]).

- Reconfigure nginx to listen on the wildcard address instead, so 
  it won't try to bind on IP addresses not yet available when it 
  starts.

Hope this helps.

[1] https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/

-- 
Maxim Dounin
http://mdounin.ru/
N
  • 16 Feb '23
Hello,

Thanks for replying. I appreciate the thorough response!
I found the solution online.
And it worked!

nano /etc/sysctl.conf # allow processes to bind to the non-local address net.ipv4.ip_nonlocal_bind = 1
sysctl -p /etc/sysctl.conf

What do you think about it?

Thanks.

From: nginx <nginx-bounces at nginx.org> on behalf of Maxim Dounin <mdounin at mdounin.ru>
Date: Thursday, February 16, 2023 at 22:19
To: nginx at nginx.org <nginx at nginx.org>
Subject: Re: nginx does not start automatically, what have I done?
Hello!

On Thu, Feb 16, 2023 at 02:48:23PM +0800, JK wrote:

>    Hello, it is my first time posting here, and I appreciate the
>    opportunity to share my experience with nginx.
>
>
>    Just to give you background, I am using a VPS from Racknerd, and I use
>    CWP (Control Web Panel), which is pretty similar to cPanel.
>
>
>    I tried to update the repo and use dnf upgrade -y, and what happened
>    was, after restarting the server, nginx did not start automatically.
>
>
>    Here is the log of nginx:
>
>
>    ● nginx.service - The nginx HTTP and reverse proxy server
>       Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled;
>    vendor preset: disabled)
>       Active: failed (Result: exit-code) since Wed 2023-02-15 17:29:03
>    EST; 7h ago
>      Process: 779 ExecStartPre=/usr/sbin/nginx -t (code=exited,
>    status=1/FAILURE)
>      Process: 776 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited,
>    status=0/SUCCESS)
>    Feb 15 17:29:02 racknerd-f5**** systemd[1]: Starting The nginx HTTP and
>    reverse proxy server...
>    Feb 15 17:29:02 racknerd-f5**** nginx[779]: nginx: the configuration
>    file /etc/nginx/nginx.conf syntax is ok
>    Feb 15 17:29:03 racknerd-f5**** nginx[779]: nginx: [emerg] bind() to
>    100.xx.xx.xx:80 failed (99: Cannot assign requested address)
>    Feb 15 17:29:03 racknerd-f5**** nginx[779]: nginx: configuration file
>    /etc/nginx/nginx.conf test failed
>    Feb 15 17:29:03 racknerd-f5**** systemd[1]: nginx.service: Control
>    process exited, code=exited status=1
>    Feb 15 17:29:03 racknerd-f5**** systemd[1]: nginx.service: Failed with
>    result 'exit-code'.
>    Feb 15 17:29:03 racknerd-f5**** systemd[1]: Failed to start The nginx
>    HTTP and reverse proxy server.
>
>
>    The solution is to manually start nginx after a minute or two.

The error message "bind() to 100.xx.xx.xx:80 failed (99: Cannot
assign requested address)" suggests the IP address you are trying
to use is not available when nginx starts.

Possible options to fix this include:

- Make sure nginx systemd service properly depends on the network
  being available (After=/Wants= network-online.target is usually
  good enough, though you may need to also enable proper wait
  service, see [1]).

- Reconfigure nginx to listen on the wildcard address instead, so
  it won't try to bind on IP addresses not yet available when it
  starts.

Hope this helps.

[1] https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx mailing list
nginx at nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20230216/649a0efa/attachment.htm>
M
  • 17 Feb '23
Hello!

On Thu, Feb 16, 2023 at 03:13:59PM +0000, nginx at onekarlo.com wrote:

> Thanks for replying. I appreciate the thorough response!
> I found the solution online.
> And it worked!
> 
> nano /etc/sysctl.conf # allow processes to bind to the non-local address net.ipv4.ip_nonlocal_bind = 1
> sysctl -p /etc/sysctl.conf
> 
> What do you think about it?

It should work around the issue, though the obvious downside is 
that the whole system will not be able to detect real errors, such 
as mistyped local addresses.

A better solution might be to ensure proper startup order.  This 
should also fix other potential issues, such as non-working DNS 
resolution during nginx startup.

On the other hand, if it works for you, it's probably good enough.

-- 
Maxim Dounin
http://mdounin.ru/
N
  • 17 Feb '23
How will I be able to fix it and avoid the use of this method?

Please do help me, thanks!

From: nginx <nginx-bounces at nginx.org> on behalf of Maxim Dounin <mdounin at mdounin.ru>
Date: Friday, February 17, 2023 at 19:30
To: nginx at nginx.org <nginx at nginx.org>
Subject: Re: nginx does not start automatically, what have I done?
Hello!

On Thu, Feb 16, 2023 at 03:13:59PM +0000, nginx at onekarlo.com wrote:

> Thanks for replying. I appreciate the thorough response!
> I found the solution online.
> And it worked!
>
> nano /etc/sysctl.conf # allow processes to bind to the non-local address net.ipv4.ip_nonlocal_bind = 1
> sysctl -p /etc/sysctl.conf
>
> What do you think about it?

It should work around the issue, though the obvious downside is
that the whole system will not be able to detect real errors, such
as mistyped local addresses.

A better solution might be to ensure proper startup order.  This
should also fix other potential issues, such as non-working DNS
resolution during nginx startup.

On the other hand, if it works for you, it's probably good enough.

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx mailing list
nginx at nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20230217/a77d9baa/attachment.htm>
M
  • 17 Feb '23
Hello!

On Fri, Feb 17, 2023 at 12:34:23PM +0000, nginx at onekarlo.com wrote:

> How will I be able to fix it and avoid the use of this method?
> 
> Please do help me, thanks!

As suggested in the original response, first thing to check is the 
systemd service you are using to start nginx.  It should contain
"After=" and "Wants=" clauses with "network-online.target", see 
http://hg.nginx.org/pkg-oss/file/tip/debian/debian/nginx.service 
for an example.

-- 
Maxim Dounin
http://mdounin.ru/
N
  • 17 Feb '23
Oh, wait. I am using AlmaLinux and CWP (Control Web Panel) which was known before as CentOS Web Panel.

From: nginx <nginx-bounces at nginx.org> on behalf of Maxim Dounin <mdounin at mdounin.ru>
Date: Friday, February 17, 2023 at 21:06
To: nginx at nginx.org <nginx at nginx.org>
Subject: Re: nginx does not start automatically, what have I done?
Hello!

On Fri, Feb 17, 2023 at 12:34:23PM +0000, nginx at onekarlo.com wrote:

> How will I be able to fix it and avoid the use of this method?
>
> Please do help me, thanks!

As suggested in the original response, first thing to check is the
systemd service you are using to start nginx.  It should contain
"After=" and "Wants=" clauses with "network-online.target", see
http://hg.nginx.org/pkg-oss/file/tip/debian/debian/nginx.service
for an example.

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx mailing list
nginx at nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20230217/2d9951ea/attachment.htm>