2

Currently, I've set up a nextcloud server with nginx and I enabled it with sudo systemctl enable nginx.service. When I'm rebooting, than I'm getting an error message which complains about a proxy server and if I take a look into sudo systemctl status nginx.service, than I'm getting this:

nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/etc/systemd/system/nginx.service; enabled; vendor preset: disabled)
     Active: failed (Result: exit-code) since Sat 2020-11-14 12:20:55 CET; 16min ago

Nov 14 12:20:55 TORNAX-ARCH systemd[1]: Starting A high performance web server and a reverse proxy server...
Nov 14 12:20:55 TORNAX-ARCH nginx[473]: 2020/11/14 12:20:55 [warn] 473#473: could not build optimal types_hash, you should increase either types_hash_max_size: 1024 or types_hash_bucket_si>
Nov 14 12:20:55 TORNAX-ARCH nginx[473]: 2020/11/14 12:20:55 [emerg] 473#473: bind() to 192.168.178.35:443 failed (99: Unknown error)
Nov 14 12:20:55 TORNAX-ARCH systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
Nov 14 12:20:55 TORNAX-ARCH systemd[1]: nginx.service: Failed with result 'exit-code'.
Nov 14 12:20:55 TORNAX-ARCH systemd[1]: Failed to start A high performance web server and a reverse proxy server.

If I run nginx -t than I'm getting this:

2020/11/14 12:37:40 [warn] 68391#68391: could not build optimal types_hash, you should increase either types_hash_max_size: 1024 or types_hash_bucket_size: 64; ignoring types_hash_bucket_size
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
2020/11/14 12:37:40 [emerg] 68391#68391: open() "/run/nginx.pid" failed (13: Permission denied)
nginx: configuration file /etc/nginx/nginx.conf test failed

When I'm looking for a solution about this open() "/run/nginx.pid" failed (13: Permission denied) error, than I'm only getting solutions for docker + nginx like these posts:

It works after restarting manually the service with sudo systemctl restart nginx.service but I'm still getting the open() "/run/nginx.pid" failed (13: Permission denied) when I'm running nginx -t.

What am I doing wrong or what can I do in order to solve this problem?

TornaxO7
  • 133
  • 1
  • 1
  • 6
  • Run `nginx -t` as root. This is a red herring. – Michael Hampton Nov 15 '20 at 00:27
  • If I run it with root, everything looks fine (except the `types_hash_max_size` error). – TornaxO7 Nov 15 '20 at 22:38
  • Of course it does. That's because it is completely irrelevant to the problem, as I already said. The actual problem is `Nov 14 12:20:55 TORNAX-ARCH nginx[473]: 2020/11/14 12:20:55 [emerg] 473#473: bind() to 192.168.178.35:443 failed (99: Unknown error)` – Michael Hampton Nov 15 '20 at 22:40
  • I think that I'll create a new question for that since my main question has been answered. – TornaxO7 Feb 09 '21 at 08:44

2 Answers2

7

sudo nginx -t

This comment should have been an answer imo.

Run nginx -t as root. This is a red herring. – Michael Hampton Nov 15 at 0:27

alexandru
  • 71
  • 3
  • Well yes, it's a part of the answer, but I still've got a problem when I'm rebooting my system as Michael Hampton pointed out. – TornaxO7 Dec 10 '20 at 12:52
2

It may be a bug. "This behavior is a known bug, caused by a race condition between nginx and systemd. Systemd is expecting the PID file to be populated before nginx had the time to create it." https://www.cloudinsidr.com/content/heres-fix-nginx-error-failed-read-pid-file-linux/

Michael S
  • 36
  • 1
  • Wohooo! Thank you! It works!!!! – TornaxO7 Jun 02 '21 at 20:30
  • That link is bad. What needs to be done? I have this as well. @TornaxO7 – Rich_F Aug 03 '22 at 23:21
  • I don't exactly know how I did that but I just know that you need to let the service wait a bit. I guess something like `ExecStart=sleep 1 && /usr/bin/nginx -g 'pid /run/nginx.pid; error_log stderr;'` should work – TornaxO7 Aug 05 '22 at 11:45