Score:1

NGINX Already enabled but not starting after reboot

ae flag

I already enable nginx on Ubuntu 20.04, but nginx doesn't automatically start after reboot.

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 Sun 2022-01-23 07:33:50 WIB; 19s ago
       Docs: man:nginx(8)
    Process: 464 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)

But I can start it manually.

nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2022-01-23 07:34:17 WIB; 2s ago
       Docs: man:nginx(8)
    Process: 891 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 901 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 902 (nginx)
      Tasks: 2 (limit: 499)
     Memory: 2.8M
     CGroup: /system.slice/nginx.service
             ├─902 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
             └─903 nginx: worker process

How can I auto start nginx everytime I restart??

drookie avatar
za flag
Something is causing nginx to exit during boot-up. Later this condition is met, so it starts up manually just fine. Examine the main `error.log`.
Score:-1
sa flag

I can't comment as I would say the existing answer should work, maybe you should debug this using journalctl? plus you can see that nginx is encountering an error in the first log entry you provided

 Active: failed (Result: exit-code) since Sun 2022-01-23 07:33:50 WIB; 19s ago

However, a workaround and this is the last case scenario would be adding a @reboot line into crontab? but I don't want to recommend this as controlling services should be done the correct way.

Score:-2
co flag

You can have the service start automatically when the machine is rebooted, with the following commands:

sudo systemctl enable nginx or sudo service nginx enable

Have a nice day!

in flag
It is already enabled.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.