Systemctl 配置 Nginx 自启动显示超时

2018-08-04 16:45:56 +08:00
 RobertYang

nginx.service 是这样编写的

    [Unit]
    Description=A high performance web server and a reverse proxy server
    After=network.target network-online.target nss-lookup.target

    [Service]
    Type=forking
    PIDFile=/usr/local/nginx/logs/nginx.pid
    PrivateDevices=yes
    SyslogLevel=err

    ExecStart=/usr/local/nginx/sbin/nginx -g 'pid /usr/local/nginx/logs/nginx.pid; error_log stderr;'
    ExecReload=/usr/local/nginx/sbin/nginx -s reload
    KillMode=mixed

    [Install]
    WantedBy=multi-user.target

开机后 Nginx 没有正确启动

    $ sudo systemctl status nginx
    * nginx.service - A high performance web server and a reverse proxy server
       Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
       Active: failed (Result: timeout) since Sat 2018-08-04 16:26:14 CST; 10s ago

    Aug 04 16:24:44 isthnew systemd[1]: Starting A high performance web server and a reverse proxy server...
    Aug 04 16:26:14 isthnew systemd[1]: nginx.service: Start operation timed out. Terminating.
    Aug 04 16:26:14 isthnew systemd[1]: nginx.service: Failed with result 'timeout'.
    Aug 04 16:26:14 isthnew systemd[1]: Failed to start A high performance web server and a reverse proxy server.

系统是 Arch,nginx 版本 1.15.2,貌似很早之前就出现过了,但是没注意,开机后使用 sudo systemctl start nginx 来启动 nginx 一问题都没有。

6874 次点击
所在节点    NGINX
28 条回复
winterbells
2018-08-05 01:19:25 +08:00
@RobertYang 那就不知道了 Nginx 文件权限多少呢 chmod +x ?
RobertYang
2018-08-05 02:04:32 +08:00
@winterbells 能手动 systemctl start nginx 所以跟配置没关系吧
henryshen233
2018-08-05 08:49:53 +08:00
@iUnix 以前的事情啦,有些进程就是这样,不过我现在没弄了😄
Hardrain
2018-08-05 09:46:38 +08:00
@RobertYang 你的意思是"Nginx 开机后不能自动由 systemd 启动,但可以手动执行 systemctl start nginx.service 来启动"是吗?

检查一下 /usr/lib/tmpfiles.d 目录,有无 nginx 相关的文件。
可能 nginx 要在一个 tmpfs 的挂载点的某个子目录下创建 lock 或 pidfile,而这个子目录重启后没被创建。
需要用 tmpfiles 解决。syntax 参考该目录下其他文件即可。
RobertYang
2018-08-05 11:07:45 +08:00
@Hardrain 应该不是这个原因,保存 pidfile 的目录早就已经创建在 /usr/local/nginx 中了
hcymk2
2018-08-05 15:25:33 +08:00
systemd.log_level=debug 再看下日志。
alvinbone88
2018-08-05 16:35:10 +08:00
RobertYang
2018-08-05 21:43:36 +08:00
@alvinbone88 肯定不是这个原因,我都是这样写的`listen 80;`

@hcymk2 不纠结了,上面也没什么重要的东西,重装了下,主要是上次腾讯云母机宕机重启,nginx 没起来博客挂了半天

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/476872

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX