AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 1250538
Accepted
Roman
Roman
Asked: 2020-06-16 04:01:30 +0800 CST2020-06-16 04:01:30 +0800 CST 2020-06-16 04:01:30 +0800 CST

重启后自动启动nginx

  • 772

我正在使用 crontab 重新启动后启动一些服务。

这是我当前的 crontab:

@reboot root /etc/init.d/nginx reload
@reboot /usr/local/bin/forever start /var/www/rtc/index.js

它适用于forever,但 nginx 永远不会启动。

我也试过:

@reboot /etc/init.d/nginx reload
@reboot sudo service nginx reload

有任何想法吗?

我的 nginx 配置文件如下所示:

server {
        listen 443 ssl;
        server_name www.example.com;

        ssl_certificate /var/wwwssl/example.pem;
        ssl_certificate_key /var/wwwssl/example.key.pem;

        location / {
                proxy_pass https://www.example.com:8443;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
        }
}

编辑:

该解决方案也不起作用

使用 systemd 插件来做到这一点:

[Service]
Restart=always

您将其作为文件放置/etc/systemd/system/nginx.service.d/override.conf(如果目录不存在,则创建目录)。您也可以使用systemctl edit nginx来创建文件。

编辑:

服务已启用。

# systemctl is-enabled nginx
enabled

我仍然不知道为什么 nginx 不启动。

每次shutdown -r(我用它来测试重新启动)之后,我都会检查sudo service --status-all并且 nginx 没有运行。

编辑

重新启动后,系统日志显示 nginx 的一些错误:

nginx: [emerg] host not found in upstream "www.example.com" in /etc/nginx/sites-enabled/default:100
nginx: configuration file /etc/nginx/nginx.conf test failed
nginx.service: Control process exited, code=exited, status=1/FAILURE
nginx.service: Failed with result 'exit-code'.
Failed to start A high performance web server and a reverse proxy server.

编辑:

尝试添加解析器:

resolver IP valid=30s;

还是同样的问题

编辑

可能是重启后nginx无法启动,因为启动顺序?Nginx 必须由 root 启动。节点应用程序由 nodeuser 使用 crontab 启动。

手动它工作:

  1. 我重新启动服务器
  2. 重新启动后,节点应用程序正在运行(crontab 启动永久进程)
  3. Nginx 有错误
  4. 我开始 nginxservice nginx restart

我认为导致问题的原因是:

重新启动后,首先处理根进程。Nginx 尝试启动,但节点应用程序还没有启动,所以它出错了。但是我该如何解决呢?

我似乎顺序没有区别。我删除了永远启动,重新启动后出现相同的错误。

nginx -t:

在此处输入图像描述

server cron nginx
  • 2 2 个回答
  • 9156 Views

2 个回答

  • Voted
  1. Adrián
    2020-06-16T14:33:02+08:002020-06-16T14:33:02+08:00

    罗马:

    sudo systemctl enable nginx
    

    您可以尝试使用此命令将指向 init 的链接设置为 SysV 吗?

    update-rc.d nginx defaults
    

    为什么要设置 nginx 默认值?

    When  run  with  the  defaults  option,  update-rc.d  makes links named
           /etc/rcrunlevel.d/[SK]NNname that point to the script /etc/init.d/name,
           using  runlevel  and  dependency information from the init.d script LSB
           comment header.
    
    • 2
  2. Best Answer
    Roman
    2020-06-24T03:45:10+08:002020-06-24T03:45:10+08:00

    该堆栈主题中也解释了该解决方案

    我不得不proxy_pass用 IP 替换 nginx 配置中的域:

    proxy_pass https://<IP-OF-YOUR-SERVER>:8443;
    
    • 2

相关问题

  • 使用 dpkg 手动安装软件包是否会阻止未来的升级路径?

  • 如何从命令行刻录双层 dvd iso

  • 如果在服务器机器上运行 Ubuntu 桌面版,性能损失是多少?

  • 将桌面版剥离为服务器版的最简单方法是什么?

  • 如何与无头服务器进行图形交互?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve