NGINX 必须在 Raspberry Pi 上频繁重启

NGINX 必须在 Raspberry Pi 上频繁重启

我设立了一个希泰亚在我的 Raspberry Pi 3B 上运行最新的饮食派。我安装了nginx作为反向代理希泰亚我托管的网站。一切都运行良好,只是几个小时后(有时更频繁)网站就无法访问了。一旦nginx服务重新启动后,一切都立即恢复正常。所以现在我必须非常频繁地重新启动服务。作为临时解决方法,我已经设置了一个每小时重新启动反向代理的 cronjob,但显然这还不够频繁。没有error.log任何内容。我该如何确定和解决问题?

代理再次失败,所以我检查了 error.log,它肯定是空的。输出service nginx status如下:

● 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'.

答案1

因此,我专注于错误 nginx[19805]: nginx: [emerg] host not found in upstream 并找到了一个可行的解决方案,如下所述这里

我编辑了我的git.domain.tld.vhost文件/etc/nginx/sites-available,使它看起来像这样:

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

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

如您所见,我将要重定向到的域分配给一个变量。我还将设置resolver为域所在的 DNS 地址。现在一切都正常了。

相关内容