Apache and ngnix won't start

I did a fresh install, I also tried to redo it, I’m on Ubuntu 24.04

PS: I have seen this happen when changing port of Hestia login

sudo tail -n 50 /var/log/apache2/error.log


[Tue Jul 22 15:03:44.522904 2025] [proxy_fcgi:error] [pid 182844:tid 137412269287104] [client XX.XXX.XXX.XX:0] AH01071: Got error 'Primary script unknown'

[Tue Jul 22 15:03:44.549890 2025] [proxy_fcgi:error] [pid 182844:tid 137412839700160] [client XX.XXX.XXX.XX:0] AH01071: Got error 'Primary script unknown'

[Tue Jul 22 15:03:44.574750 2025] [proxy_fcgi:error] [pid 182843:tid 137412277679808] [client XX.XXX.XXX.XX:0] AH01071: Got error 'Primary script unknown'

[Tue Jul 22 15:03:44.601190 2025] [proxy_fcgi:error] [pid 182844:tid 137412260894400] [client XX.XXX.XXX.XX:0] AH01071: Got error 'Primary script unknown'

[Tue Jul 22 15:03:44.705705 2025] [proxy_fcgi:error] [pid 182843:tid 137411757594304] [client XX.XXX.XXX.XX:0] AH01071: Got error 'Primary script unknown'

[Tue Jul 22 15:03:44.730579 2025] [proxy_fcgi:error] [pid 182844:tid 137411740808896] [client XX.XXX.XXX.XX:0] AH01071: Got error 'Primary script unknown'

[Tue Jul 22 15:03:44.808856 2025] [proxy_fcgi:error] [pid 182844:tid 137412286072512] [client XX.XXX.XXX.XX:0] AH01071: Got error 'Primary script unknown'

[Tue Jul 22 15:03:44.835771 2025] [proxy_fcgi:error] [pid 182843:tid 137411774379712] [client XX.XXX.XXX.XX:0] AH01071: Got error 'Primary script unknown'

[Tue Jul 22 15:03:44.862153 2025] [proxy_fcgi:error] [pid 182844:tid 137411237508800] [client XX.XXX.XXX.XX:0] AH01071: Got error 'Primary script unknown'

[Tue Jul 22 15:03:44.887450 2025] [proxy_fcgi:error] [pid 182844:tid 137411774379712] [client XX.XXX.XXX.XX:0] AH01071: Got error 'Primary script unknown'

[Tue Jul 22 15:03:44.912928 2025] [proxy_fcgi:error] [pid 182844:tid 137412277679808] [client XX.XXX.XXX.XX:0] AH01071: Got error 'Primary script unknown'

[Tue Jul 22 15:03:44.938023 2025] [proxy_fcgi:error] [pid 182844:tid 137411757594304] [client XX.XXX.XXX.XX:0] AH01071: Got error 'Primary script unknown'

[Tue Jul 22 15:03:44.963416 2025] [proxy_fcgi:error] [pid 182844:tid 137411212330688] [client XX.XXX.XXX.XX:0] AH01071: Got error 'Primary script unknown'

[Tue Jul 22 15:03:44.988886 2025] [proxy_fcgi:error] [pid 182844:tid 137412814522048] [client XX.XXX.XXX.XX:0] AH01071: Got error 'Primary script unknown'

[Tue Jul 22 15:03:45.014713 2025] [proxy_fcgi:error] [pid 182843:tid 137411765987008] [client XX.XXX.XXX.XX:0] AH01071: Got error 'Primary script unknown'

[Tue Jul 22 15:03:45.042694 2025] [proxy_fcgi:error] [pid 182843:tid 137412831307456] [client XX.XXX.XXX.XX:0] AH01071: Got error 'Primary script unknown'

[Tue Jul 22 15:03:45.092540 2025] [proxy_fcgi:error] [pid 182844:tid 137412294465216] [client XX.XXX.XXX.XX:0] AH01071: Got error 'Primary script unknown'

[Tue Jul 22 15:03:45.119362 2025] [proxy_fcgi:error] [pid 182844:tid 137411229116096] [client XX.XXX.XXX.XX:0] AH01071: Got error 'Primary script unknown'

[Tue Jul 22 15:03:45.145043 2025] [proxy_fcgi:error] [pid 182843:tid 137411732416192] [client XX.XXX.XXX.XX:0] AH01071: Got error 'Primary script unknown'

[Tue Jul 22 15:03:45.171320 2025] [proxy_fcgi:error] [pid 182844:tid 137412831307456] [client XX.XXX.XXX.XX:0] AH01071: Got error 'Primary script unknown'

[Tue Jul 22 15:03:45.197022 2025] [proxy_fcgi:error] [pid 182844:tid 137412848092864] [client XX.XXX.XXX.XX:0] AH01071: Got error 'Primary script unknown'

[Tue Jul 22 15:03:45.225198 2025] [proxy_fcgi:error] [pid 182844:tid 137412797736640] [client XX.XXX.XXX.XX:0] AH01071: Got error 'Primary script unknown'

[Tue Jul 22 15:03:45.250227 2025] [proxy_fcgi:error] [pid 182844:tid 137412822914752] [client XX.XXX.XXX.XX:0] AH01071: Got error 'Primary script unknown'

[Tue Jul 22 15:03:45.275447 2025] [proxy_fcgi:error] [pid 182844:tid 137412311250624] [client XX.XXX.XXX.XX:0] AH01071: Got error 'Primary script unknown'

[Tue Jul 22 15:03:45.326021 2025] [proxy_fcgi:error] [pid 182844:tid 137411732416192] [client XX.XXX.XXX.XX:0] AH01071: Got error 'Primary script unknown'

[Tue Jul 22 15:03:45.385447 2025] [proxy_fcgi:error] [pid 182844:tid 137411220723392] [client XX.XXX.XXX.XX:0] AH01071: Got error 'Primary script unknown'

[Tue Jul 22 15:03:45.410388 2025] [proxy_fcgi:error] [pid 182843:tid 137412294465216] [client XX.XXX.XXX.XX:0] AH01071: Got error 'Primary script unknown'

[Tue Jul 22 15:03:45.435016 2025] [proxy_fcgi:error] [pid 182844:tid 137412269287104] [client XX.XXX.XXX.XX:0] AH01071: Got error 'Primary script unknown'

[Tue Jul 22 15:03:45.459281 2025] [proxy_fcgi:error] [pid 182844:tid 137412839700160] [client XX.XXX.XXX.XX:0] AH01071: Got error 'Primary script unknown'

[Tue Jul 22 15:03:45.484029 2025] [proxy_fcgi:error] [pid 182844:tid 137412260894400] [client XX.XXX.XXX.XX:0] AH01071: Got error 'Primary script unknown'

[Tue Jul 22 15:03:45.509645 2025] [proxy_fcgi:error] [pid 182843:tid 137411740808896] [client XX.XXX.XXX.XX:0] AH01071: Got error 'Primary script unknown'

[Tue Jul 22 15:03:45.534787 2025] [proxy_fcgi:error] [pid 182843:tid 137411220723392] [client XX.XXX.XXX.XX:0] AH01071: Got error 'Primary script unknown'

[Tue Jul 22 15:03:45.559983 2025] [proxy_fcgi:error] [pid 182844:tid 137411749201600] [client XX.XXX.XXX.XX:0] AH01071: Got error 'Primary script unknown'

[Tue Jul 22 15:03:45.584579 2025] [proxy_fcgi:error] [pid 182843:tid 137412814522048] [client XX.XXX.XXX.XX:0] AH01071: Got error 'Primary script unknown'

[Tue Jul 22 15:03:45.608979 2025] [proxy_fcgi:error] [pid 182844:tid 137412302857920] [client XX.XXX.XXX.XX:0] AH01071: Got error 'Primary script unknown'

[Tue Jul 22 15:03:45.635250 2025] [proxy_fcgi:error] [pid 182844:tid 137411740808896] [client XX.XXX.XXX.XX:0] AH01071: Got error 'Primary script unknown'

[Tue Jul 22 15:22:12.425845 2025] [mpm_event:notice] [pid 5362:tid 137412872599424] AH00493: SIGUSR1 received. Doing graceful restart

[Tue Jul 22 15:22:13.399605 2025] [ssl:warn] [pid 5362:tid 137412872599424] AH01909: 51.254.198.200:443:0 server certificate does NOT include an ID which matches the server name

[Tue Jul 22 15:22:13.399950 2025] [mpm_event:notice] [pid 5362:tid 137412872599424] AH00489: Apache/2.4.58 (Ubuntu) mod_fcgid/2.3.9 OpenSSL/3.0.13 configured -- resuming normal operations

[Tue Jul 22 15:22:13.399970 2025] [core:notice] [pid 5362:tid 137412872599424] AH00094: Command line: '/usr/sbin/apache2'

[Tue Jul 22 15:28:31.272367 2025] [mpm_event:notice] [pid 5362:tid 137412872599424] AH00493: SIGUSR1 received. Doing graceful restart

[Tue Jul 22 15:28:31.361729 2025] [ssl:warn] [pid 5362:tid 137412872599424] AH01909: 51.254.198.200:443:0 server certificate does NOT include an ID which matches the server name

[Tue Jul 22 15:28:31.362040 2025] [mpm_event:notice] [pid 5362:tid 137412872599424] AH00489: Apache/2.4.58 (Ubuntu) mod_fcgid/2.3.9 OpenSSL/3.0.13 configured -- resuming normal operations

[Tue Jul 22 15:28:31.362059 2025] [core:notice] [pid 5362:tid 137412872599424] AH00094: Command line: '/usr/sbin/apache2'

[Tue Jul 22 15:44:49.333616 2025] [mpm_event:notice] [pid 5362:tid 137412872599424] AH00492: caught SIGWINCH, shutting down gracefully

[Tue Jul 22 15:49:21.129426 2025] [ssl:warn] [pid 3310:tid 132582098683776] AH01909: 51.254.198.200:443:0 server certificate does NOT include an ID which matches the server name

[Tue Jul 22 15:49:21.130033 2025] [suexec:notice] [pid 3310:tid 132582098683776] AH01232: suEXEC mechanism enabled (wrapper: /usr/lib/apache2/suexec)

[Tue Jul 22 15:49:21.166041 2025] [ssl:warn] [pid 3311:tid 132582098683776] AH01909: 51.254.198.200:443:0 server certificate does NOT include an ID which matches the server name

[Tue Jul 22 15:49:21.167207 2025] [mpm_event:notice] [pid 3311:tid 132582098683776] AH00489: Apache/2.4.58 (Ubuntu) mod_fcgid/2.3.9 OpenSSL/3.0.13 configured -- resuming normal operations

[Tue Jul 22 15:49:21.167224 2025] [core:notice] [pid 3311:tid 132582098683776] AH00094: Command line: '/usr/sbin/apache2'

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


2025/07/22 15:28:31 [warn] 196999#196999: "ssl_stapling" ignored, issuer certificate not found for certificate "/home/site/conf/web/site1.com/ssl/site1.com.pem"

2025/07/22 15:28:31 [warn] 196999#196999: "ssl_stapling" ignored, issuer certificate not found for certificate "/home/site/conf/web/site2.it/ssl/site2.it.pem"

2025/07/22 15:28:31 [warn] 196999#196999: "ssl_stapling" ignored, issuer certificate not found for certificate "/home/site/conf/web/site3.dev/ssl/site3.dev.pem"

2025/07/22 15:28:31 [warn] 196999#196999: "ssl_stapling" ignored, issuer certificate not found for certificate "/home/site/conf/web/site4.space/ssl/site4.space.pem"

2025/07/22 15:28:31 [warn] 196999#196999: "ssl_stapling" ignored, issuer certificate not found for certificate "/home/site/conf/web/site5.org/ssl/site5.org.pem"

2025/07/22 15:28:31 [warn] 196999#196999: "ssl_stapling" ignored, issuer certificate not found for certificate "/home/site/conf/web/site6.eu/ssl/site6.eu.pem"

2025/07/22 15:28:31 [warn] 196999#196999: "ssl_stapling" ignored, issuer certificate not found for certificate "/home/site/conf/web/site7.it/ssl/site7.it.pem"

2025/07/22 15:28:31 [warn] 196999#196999: "ssl_stapling" ignored, issuer certificate not found for certificate "/home/site/conf/web/site8.dev/ssl/site8.dev.pem"

2025/07/22 15:28:56 [crit] 197058#197058: unlink() "/var/cache/nginx/site5.org/6/00/0b8531f8a3e82d4e6810e1fc4f507006" failed (2: No such file or directory)

...

2025/07/22 15:39:08 [crit] 197058#197058: unlink() "/var/cache/nginx/site9.com/3/b9/038fefe30da6f590c5edcfa0aa12eb93" failed (2: No such file or directory)

...

2025/07/22 15:48:09 [warn] 1231#1231: "ssl_stapling" ignored, issuer certificate not found for certificate "/home/site/conf/web/site10.org/ssl/site10.org.pem"

2025/07/22 15:48:09 [warn] 1231#1231: "ssl_stapling" ignored, issuer certificate not found for certificate "/home/site/conf/web/site11.it/ssl/site11.it.pem"

2025/07/22 15:48:09 [warn] 1231#1231: "ssl_stapling" ignored, issuer certificate not found for certificate "/home/site/conf/web/site12.ch/ssl/site12.ch.pem"

...

2025/07/22 15:48:09 [emerg] 1231#1231: bind() to XX.XXX.XXX.XXX:80 failed (99: Cannot assign requested address)

Show the output of this command:

lsof -Pn +c0 -i:80,443,8080,8443 -sTCP:LISTEN

Thank for supp <3 on the installation i used port 2083

root@webp:/home/ubuntu# lsof -Pn +c0 -i:80,443,8080,2083,8443 -sTCP:LISTEN
COMMAND         PID      USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
hestia-nginx   1455      root    6u  IPv4   5756      0t0  TCP *:2083 (LISTEN)
hestia-nginx   1455      root    7u  IPv6   5757      0t0  TCP *:2083 (LISTEN)
hestia-nginx   1456 hestiaweb    6u  IPv4   5756      0t0  TCP *:2083 (LISTEN)
hestia-nginx   1456 hestiaweb    7u  IPv6   5757      0t0  TCP *:2083 (LISTEN)
nginx          3781      root   51u  IPv4  23125      0t0  TCP XX.XXX.XXX.XXX:80 (LISTEN)
nginx          3781      root   52u  IPv4  23126      0t0  TCP XX.XXX.XXX.XXX:443 (LISTEN)
apache2        4221      root    4u  IPv4  26758      0t0  TCP XX.XXX.XXX.XXX:8443 (LISTEN)
apache2        4221      root    5u  IPv4  26760      0t0  TCP XX.XXX.XXX.XXX:8080 (LISTEN)
nginx        101502  www-data   51u  IPv4  23125      0t0  TCP XX.XXX.XXX.XXX:80 (LISTEN)
nginx        101502  www-data   52u  IPv4  23126      0t0  TCP XX.XXX.XXX.XXX:443 (LISTEN)
nginx        101504  www-data   51u  IPv4  23125      0t0  TCP XX.XXX.XXX.XXX:80 (LISTEN)
nginx        101504  www-data   52u  IPv4  23126      0t0  TCP XX.XXX.XXX.XXX:443 (LISTEN)
nginx        101505  www-data   51u  IPv4  23125      0t0  TCP XX.XXX.XXX.XXX:80 (LISTEN)
nginx        101505  www-data   52u  IPv4  23126      0t0  TCP XX.XXX.XXX.XXX:443 (LISTEN)
nginx        101506  www-data   51u  IPv4  23125      0t0  TCP XX.XXX.XXX.XXX:80 (LISTEN)
nginx        101506  www-data   52u  IPv4  23126      0t0  TCP XX.XXX.XXX.XXX:443 (LISTEN)
nginx        101507  www-data   51u  IPv4  23125      0t0  TCP XX.XXX.XXX.XXX:80 (LISTEN)
nginx        101507  www-data   52u  IPv4  23126      0t0  TCP XX.XXX.XXX.XXX:443 (LISTEN)
nginx        101508  www-data   51u  IPv4  23125      0t0  TCP XX.XXX.XXX.XXX:80 (LISTEN)
nginx        101508  www-data   52u  IPv4  23126      0t0  TCP XX.XXX.XXX.XXX:443 (LISTEN)
nginx        101510  www-data   51u  IPv4  23125      0t0  TCP XX.XXX.XXX.XXX:80 (LISTEN)
nginx        101510  www-data   52u  IPv4  23126      0t0  TCP XX.XXX.XXX.XXX:443 (LISTEN)
nginx        101511  www-data   51u  IPv4  23125      0t0  TCP XX.XXX.XXX.XXX:80 (LISTEN)
nginx        101511  www-data   52u  IPv4  23126      0t0  TCP XX.XXX.XXX.XXX:443 (LISTEN)
nginx        101514  www-data   51u  IPv4  23125      0t0  TCP XX.XXX.XXX.XXX:80 (LISTEN)
nginx        101514  www-data   52u  IPv4  23126      0t0  TCP XX.XXX.XXX.XXX:443 (LISTEN)
nginx        101515  www-data   51u  IPv4  23125      0t0  TCP XX.XXX.XXX.XXX:80 (LISTEN)
nginx        101515  www-data   52u  IPv4  23126      0t0  TCP XX.XXX.XXX.XXX:443 (LISTEN)
nginx        101516  www-data   51u  IPv4  23125      0t0  TCP XX.XXX.XXX.XXX:80 (LISTEN)
nginx        101516  www-data   52u  IPv4  23126      0t0  TCP XX.XXX.XXX.XXX:443 (LISTEN)
nginx        101517  www-data   51u  IPv4  23125      0t0  TCP XX.XXX.XXX.XXX:80 (LISTEN)
nginx        101517  www-data   52u  IPv4  23126      0t0  TCP XX.XXX.XXX.XXX:443 (LISTEN)
apache2      101844  www-data    4u  IPv4  26758      0t0  TCP XX.XXX.XXX.XXX:8443 (LISTEN)
apache2      101844  www-data    5u  IPv4  26760      0t0  TCP XX.XXX.XXX.XXX:8080 (LISTEN)
apache2      101845  www-data    4u  IPv4  26758      0t0  TCP XX.XXX.XXX.XXX:8443 (LISTEN)
apache2      101845  www-data    5u  IPv4  26760      0t0  TCP XX.XXX.XXX.XXX:8080 (LISTEN)
apache2      101846  www-data    4u  IPv4  26758      0t0  TCP XX.XXX.XXX.XXX:8443 (LISTEN)
apache2      101846  www-data    5u  IPv4  26760      0t0  TCP XX.XXX.XXX.XXX:8080 (LISTEN)

The output looks fine.

systemctl stop nginx
systemctl stop apache
lsof -Pn +c0 -i:80,443,8080,8443 -sTCP:LISTEN

If you don’t see anything listening on port 80, 443, 8080 or 8443.

systemctl start nginx
systemctl status nginx --no-pager -l

systemctl start apache2
systemctl status apache2 --no-pager -l

first command:

root@webp:/home/ubuntu# lsof -Pn +c0 -i:80,443,8080,2083,8443 -sTCP:LISTEN
COMMAND       PID      USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
hestia-nginx 1455      root    6u  IPv4   5756      0t0  TCP *:2083 (LISTEN)
hestia-nginx 1455      root    7u  IPv6   5757      0t0  TCP *:2083 (LISTEN)
hestia-nginx 1456 hestiaweb    6u  IPv4   5756      0t0  TCP *:2083 (LISTEN)
hestia-nginx 1456 hestiaweb    7u  IPv6   5757      0t0  TCP *:2083 (LISTEN)

systemctl status nginx --no-pager -l

● nginx.service - nginx - high performance web server
     Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; preset: enabled)
     Active: active (running) since Wed 2025-07-23 14:01:09 CEST; 34s ago
       Docs: https://nginx.org/en/docs/
    Process: 115166 ExecStart=/usr/sbin/nginx -c ${CONFFILE} (code=exited, status=0/SUCCESS)
   Main PID: 115167 (nginx)
      Tasks: 15 (limit: 76923)
     Memory: 19.1M (peak: 19.8M)
        CPU: 139ms
     CGroup: /system.slice/nginx.service
             β”œβ”€115167 "nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf"
             β”œβ”€115168 "nginx: worker process"
             β”œβ”€115169 "nginx: worker process"
             β”œβ”€115170 "nginx: worker process"
             β”œβ”€115171 "nginx: worker process"
             β”œβ”€115172 "nginx: worker process"
             β”œβ”€115173 "nginx: worker process"
             β”œβ”€115174 "nginx: worker process"
             β”œβ”€115175 "nginx: worker process"
             β”œβ”€115177 "nginx: worker process"
             β”œβ”€115178 "nginx: worker process"
             β”œβ”€115179 "nginx: worker process"
             β”œβ”€115180 "nginx: worker process"
             β”œβ”€115181 "nginx: cache manager process"
             └─115182 "nginx: cache loader process"

Jul 23 14:01:09 webp.site nginx[115166]: nginx: [warn] "ssl_stapling" ignored, issuer certificate not found for certificate "/home/site/conf/web/site/ssl/site.pem"
Jul 23 14:01:09 webp.site nginx[115166]: nginx: [warn] "ssl_stapling" ignored, issuer certificate not found for certificate "/home/site/conf/web/site/ssl/site.pem"
Jul 23 14:01:09 webp.site nginx[115166]: nginx: [warn] "ssl_stapling" ignored, issuer certificate not found for certificate "/home/site/conf/web/site/ssl/site.pem"
Jul 23 14:01:09 webp.site nginx[115166]: nginx: [warn] "ssl_stapling" ignored, issuer certificate not found for certificate "/home/site/conf/web/site/ssl/site.pem"
Jul 23 14:01:09 webp.site nginx[115166]: nginx: [warn] "ssl_stapling" ignored, issuer certificate not found for certificate "/home/site/conf/web/site/ssl/site.pem"
Jul 23 14:01:09 webp.site nginx[115166]: nginx: [warn] "ssl_stapling" ignored, issuer certificate not found for certificate "/home/site/conf/web/site/ssl/site.pem"
Jul 23 14:01:09 webp.site nginx[115166]: nginx: [warn] "ssl_stapling" ignored, issuer certificate not found for certificate "/home/site/conf/web/site/ssl/site.pem"
Jul 23 14:01:09 webp.site nginx[115166]: nginx: [warn] "ssl_stapling" ignored, issuer certificate not found for certificate "/home/site/conf/web/site/ssl/siteu.pem"
Jul 23 14:01:09 webp.site nginx[115166]: nginx: [warn] "ssl_stapling" ignored, issuer certificate not found for certificate "/home/site/conf/web/site/ssl/site.pem"
Jul 23 14:01:09 webp.site systemd[1]: Started nginx.service - nginx - high performance web server.

systemctl status apache2 --no-pager -l

root@webp:/home/ubuntu# systemctl status apache2 --no-pager -l
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/usr/lib/systemd/system/apache2.service; enabled; preset: enabled)
     Active: active (running) since Wed 2025-07-23 14:02:16 CEST; 9s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 115212 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 115215 (apache2)
      Tasks: 56 (limit: 76923)
     Memory: 12.2M (peak: 13.1M)
        CPU: 100ms
     CGroup: /system.slice/apache2.service
             β”œβ”€115215 /usr/sbin/apache2 -k start
             β”œβ”€115217 /usr/sbin/apache2 -k start
             β”œβ”€115218 /usr/sbin/apache2 -k start
             └─115219 /usr/sbin/apache2 -k start

Jul 23 14:02:16 webp.site systemd[1]: Starting apache2.service - The Apache HTTP Server...
Jul 23 14:02:16 webp.site systemd[1]: Started apache2.service - The Apache HTTP Server.

It appears to be working correctly. Is there another problem?

The problem is that when I restart the server it doesn’t start automatically, I already ran systemctl enable

Then that usually means Nginx tries to start before the network is online so the ip used is not available.

Show the output of this command:

systemctl cat nginx
systemctl cat nginx
# /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=https://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
Environment="CONFFILE=/etc/nginx/nginx.conf"
EnvironmentFile=-/etc/default/nginx
ExecStart=/usr/sbin/nginx -c ${CONFFILE}
ExecReload=/bin/sh -c "/bin/kill -s HUP $(/bin/cat /run/nginx.pid)"
ExecStop=/bin/sh -c "/bin/kill -s TERM $(/bin/cat /run/nginx.pid)"

[Install]
WantedBy=multi-user.target

These two directives should be enough to wait until the network is online, but seems your server is taking more time to get the ip.

Show the output of these commands (replace enp0s3 by your actual interface name):

systemctl status NetworkManager-wait-online.service
systemctl status systemd-networkd-wait-online.service
networkctl status enp0s3 --no-pager -l
journalctl -b | grep -i enp0s3

Thanks for your patience

root@webp:/home/ubuntu# systemctl status NetworkManager-wait-online.service
Unit NetworkManager-wait-online.service could not be found.
root@webp:/home/ubuntu# systemctl status systemd-networkd-wait-online.service
● systemd-networkd-wait-online.service - Wait for Network to be Configured
     Loaded: loaded (/usr/lib/systemd/system/systemd-networkd-wait-online.service; enabled; preset: enabled)
    Drop-In: /run/systemd/system/systemd-networkd-wait-online.service.d
             └─10-netplan.conf
     Active: active (exited) since Tue 2025-07-22 18:03:31 CEST; 20h ago
       Docs: man:systemd-networkd-wait-online.service(8)
    Process: 1156 ExecStart=/lib/systemd/systemd-networkd-wait-online -i eno1:degraded (code=exited, status=0/SUCCESS)
    Process: 1158 ExecStart=/lib/systemd/systemd-networkd-wait-online --any -o routable -i eno1 (code=exited, status=0/>
   Main PID: 1158 (code=exited, status=0/SUCCESS)
        CPU: 12ms

Jul 22 18:03:26 myhost.com systemd[1]: Starting systemd-networkd-wait-online.service - Wait for Network to be C>
Jul 22 18:03:31 myhost.com systemd[1]: Finished systemd-networkd-wait-online.service - Wait for Network to be C>
 ^X
[1]+  Stopped                 systemctl status systemd-networkd-wait-online.service
root@webp:/home/ubuntu# [200~networkctl status enp0s3 --no-pager -l~
[200~networkctl: command not found
root@webp:/home/ubuntu# [200~networkctl status enp0s3 --no-pager -l
[200~networkctl: command not found
root@webp:/home/ubuntu# networkctl status enp0s3 --no-pager -l
Interface "enp0s3" not found.
root@webp:/home/ubuntu# networkctl list
IDX LINK TYPE     OPERATIONAL SETUP
  1 lo   loopback carrier     unmanaged
  2 eno1 ether    routable    configured
  3 eno2 ether    off         unmanaged

3 links listed.
root@webp:/home/ubuntu# networkctl status en01 --no-pager -l
Interface "en01" not found.
root@webp:/home/ubuntu# networkctl status eno1 --no-pager -l
● 2: eno1
                   Link File: /run/systemd/network/10-netplan-eno1.link
                Network File: /run/systemd/network/10-netplan-eno1.network
                       State: routable (configured)
                Online state: online
                        Type: ether
                        Path: pci-0000:04:00.0
                      Driver: igb
                      Vendor: Intel Corporation
                       Model: I350 Gigabit Network Connection
           Alternative Names: enp4s0f0
            Hardware Address: XXXXXXX (Super Micro Computer, Inc.)
                         MTU: 1500 (min: 68, max: 9216)
                       QDisc: mq
IPv6 Address Generation Mode: eui64
    Number of Queues (Tx/Rx): 8/8
            Auto negotiation: yes
                       Speed: 1Gbps
                      Duplex: full
                        Port: tp
                     Address: XX.XXX.XXX.XXX (DHCP4 via XX.XXX.XXX.XXX)
                              XX.XXX.XXX.XXX
                              XX.XXX.XXX.XXX
                     Gateway: XX.XXX.XXX.XXX
                              XX.XXX.XXX.XXX:aff:ff:ff:ff:ff
                         DNS: XXXXXXX
           Activation Policy: up
         Required For Online: yes
             DHCP4 Client ID: IAID:0xb6220feb/DUID

Jul 22 18:03:26 myhost.com systemd-networkd[1151]: eno1: Configuring with /run/systemd/network/10-netplan-eno1.network.
Jul 22 18:03:26 myhost.com systemd-networkd[1151]: eno1: Link UP
Jul 22 18:03:29 myhost.com systemd-networkd[1151]: eno1: Gained carrier
Jul 22 18:03:31 myhost.com systemd-networkd[1151]: eno1: Gained IPv6LL
Jul 22 18:03:34 myhost.com systemd-networkd[1151]: eno1: DHCPv4 address XX.XXX.XXX.XXX/24, gateway XX.XXX.XXX.XXX acquired from XX.XXX.XXX.XXX
root@webp:/home/ubuntu# journalctl -b | grep -i eno1
Jul 22 18:03:20 myhost.com kernel: igb 0000:04:00.0 eno1: renamed from eth0
Jul 22 18:03:26 myhost.com systemd-networkd[1151]: eno1: Configuring with /run/systemd/network/10-netplan-eno1.network.
Jul 22 18:03:26 myhost.com systemd-networkd[1151]: eno1: Link UP
Jul 22 18:03:29 myhost.com systemd-networkd[1151]: eno1: Gained carrier
Jul 22 18:03:29 myhost.com kernel: igb 0000:04:00.0 eno1: igb: eno1 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX
Jul 22 18:03:31 myhost.com systemd-networkd[1151]: eno1: Gained IPv6LL
Jul 22 18:03:31 myhost.com cloud-init[1164]: ci-info: |  eno1  |  True |  XX.XXX.XXX.XXX/128   |     .     | global | ac:1f:6b:b4:d3:cc |
Jul 22 18:03:31 myhost.com cloud-init[1164]: ci-info: |  eno1  |  True | XX.XXX.XXX.XXX/64 |     .     |  link  | ac:1f:6b:b4:d3:cc |
Jul 22 18:03:31 myhost.com cloud-init[1164]: ci-info: |   0   | XX.XXX.XXX.XXX |               ::               |    eno1   |   U   |
Jul 22 18:03:31 myhost.com cloud-init[1164]: ci-info: |   1   |       fe80::/64       |               ::               |    eno1   |   U   |
Jul 22 18:03:31 myhost.com cloud-init[1164]: ci-info: |   2   |          ::/0         | XX.XXX.XXX.XXX:aff:ff:ff:ff:ff |    eno1   |   UG  |
Jul 22 18:03:31 myhost.com cloud-init[1164]: ci-info: |   4   |         local         |               ::               |    eno1   |   U   |
Jul 22 18:03:31 myhost.com cloud-init[1164]: ci-info: |   5   |         local         |               ::               |    eno1   |   U   |
Jul 22 18:03:31 myhost.com cloud-init[1164]: ci-info: |   6   |       multicast       |               ::               |    eno1   |   U   |
Jul 22 18:03:32 myhost.com named[1210]: listening on IPv6 interface eno1, XX.XXX.XXX.XXX#53
Jul 22 18:03:32 myhost.com named[1210]: listening on IPv6 interface eno1, XX.XXX.XXX.XXX%2#53
Jul 22 18:03:34 myhost.com systemd-networkd[1151]: eno1: DHCPv4 address XX.XXX.XXX.XXX/24, gateway XX.XXX.XXX.XXX acquired from XX.XXX.XXX.XXX
Jul 22 18:03:34 myhost.com named[1210]: listening on IPv4 interface eno1, XX.XXX.XXX.XXX#53

Too many Xs, I understand you don’t want to shre the ips bu I don’t know what’s your public ip or ips, or if they are private, etc.

You could modify the nginx service to add Requires=network-online.target to the Unit block and maybe a sleep to Service block.

I would override the conf file using systemctl edit nginx and before the line ### Lines below this comment will be discarded wrote this and save the file.

[Unit]
Requires=network-online.target

[Service]
ExecStartPre=/bin/sleep 10

Once done, just in case systemctl daemon-reload and restart the server to test it.

1 Like

Unfortunately, your solution didn’t solve the problem, but you gave me a great idea.

override on Apache2

sudo systemctl edit apache2

[Unit]
After=network-online.target named.service
Wants=network-online.target

override on Nginx

systemctl edit nginx

[Unit]
After=network-online.target named.service
Wants=network-online.target

Refresh systemd

sudo systemctl daemon-reexec
sudo systemctl daemon-reload

Check services is enabled

systemctl enable apache2
systemctl enable nginx

I left the solution for posterity, NOW WORKS! <3 THANKS <3

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.