I set up a Gitea server on my Raspberry Pi 3B running the latest DietPi. I installed nginx as the reverse proxy for the Gitea website I host. Everything works perfectly, except after a couple of hours (sometimes more often) the website can't be reached. Once the nginx service is restarted, everything works fine immediately again. So for now I have to restart the service pretty frequently. As a temporary workaround, I already set up a cronjob every hour that restarts the reverse proxy, but apparently not even that is frequent enough. The error.log doesn't have any content. How can I determine and solve the issue?

The proxy failed again, so I checked the error.log and it is definitely empty. The output for service nginx status is as follows:

● 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 Fri 2018-11-09 08:05:09 CET; 17min ago
     Docs: man:nginx(8)
  Process: 14459 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, s
  Process: 6409 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
  Process: 19805 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
 Main PID: 6411 (code=exited, status=0/SUCCESS)
      CPU: 121ms

Nov 09 08:05:01 hostname systemd[1]: Starting A high performance web server and a reverse proxy server...
Nov 09 08:05:09 hostname nginx[19805]: nginx: [emerg] host not found in upstream "git.domain.tld" in /etc/nginx/sites-en
Nov 09 08:05:09 hostname nginx[19805]: nginx: configuration file /etc/nginx/nginx.conf test failed
Nov 09 08:05:09 hostname systemd[1]: nginx.service: Control process exited, code=exited status=1
Nov 09 08:05:09 hostname systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Nov 09 08:05:09 hostname systemd[1]: nginx.service: Unit entered failed state.
Nov 09 08:05:09 hostname systemd[1]: nginx.service: Failed with result 'exit-code'.
  • Perhaps running out of memory? Check your config, the error log shouldn't be empty. – Gerard H. Pille Nov 9 at 5:57
  • Does this happen even if you don't serve any sites (disable all sites) and make the nginx available only from local network? – Aulis Ronkainen Nov 9 at 7:14
  • @AulisRonkainen I edited my question. – Akito Nov 9 at 7:30
  • That (status log) says that your configuration is not correct. Can you check that, please? – Aulis Ronkainen Nov 9 at 15:35
  • I assume, it wouldn't run at all, if it was incorrect. A couple of hours ago I added a resolver and used a variable instead of the actual address for proxy_pass and so far it's working well. Once I will be sure that it worked, I will post it as an answer. – Akito Nov 9 at 15:54
up vote 0 down vote accepted

So I was focusing on the error nginx[19805]: nginx: [emerg] host not found in upstream and found a working solution, that is described here.

I edited my git.domain.tld.vhost file within /etc/nginx/sites-available so it would look like this:

server {
  resolver 8.8.8.8;
  listen 80;
  server_name git.domain.tld;

  location / {
    set $upstream "git.domain.tld:5016";
    proxy_pass http://$upstream;
  }
}

As you see here, I assigned the domain that is being redirected to, to a variable. I also set the resolver to the DNS address which the domain is on. Now everything works as it should.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.