phper 发表于 2019-6-20 14:51:29

Ubuntu 18.04.2 LTS lnmp1.6 服务器重启后 nginx不能启动

Ubuntu 18.04.2 LTS lnmp1.6服务器重启后 nginx不能启动,php mysql 都可以自启,但是 nginx 不能在系统重启后自启。希望军哥可以给点思路排除或者如何手动添加启动,谢谢!

补充内容 (2019-8-22 20:38):
解决了,按照军哥的6楼的方法 成功了

licess 发表于 2019-6-20 18:53:21

nginx配置文件是否有错误?

没错误的话可以,这样试试
echo "

WantedBy=multi-user.target
Alias=rc-local.service
" >> /etc/systemd/system/rc-local.service

echo "
#!/bin/bash
/etc/init.d/nginx start
" >> /etc/rc.local

chmod +x /etc/rc.local
然后重启一下看看

phper 发表于 2019-6-20 21:38:56

licess 发表于 2019-6-20 18:53
nginx配置文件是否有错误?

没错误的话可以,这样试试


nginx没错 貌似都没有 etc/systemd/system/rc-local.service 这个文件和路径
root@local:~# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
root@local:~# echo "
>
> WantedBy=multi-user.target
> Alias=rc-local.service
> " >> etc/systemd/system/rc-local.service
-bash: etc/systemd/system/rc-local.service: No such file or directory
root@local:~#

licess 发表于 2019-6-21 08:56:21

etc 前面漏了一个 / 加上就行了

phper 发表于 2019-6-21 11:10:35

licess 发表于 2019-6-21 08:56
etc 前面漏了一个 / 加上就行了

老哥 还是不行

licess 发表于 2019-6-21 20:49:52

echo '

Description=The NGINX HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target


Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true


WantedBy=multi-user.target
' > /etc/systemd/system/nginx.service

chmod +x /etc/systemd/system/nginx.service
systemctl enable nginx.service
还是不行就很可能你系统上有问题,也没其他版本可以试了

cyccc 发表于 2019-7-30 18:46:41

phper 发表于 2019-6-21 11:10
老哥 还是不行

你看下 ls /lib/systemd/system/rc*    有没有rc.local.service

如果有,
你就 建立一个rc.local文件
sudotouch /etc/rc.local
给它添加执行权限
sudo chmod 775 /etc/rc.local
编辑rc.local
sudo vim /etc/rc.local

输入如下内容:
#!/bin/bash

/etc/init.d/nginx start

然后你重启机器试试

phper 发表于 2019-8-22 20:36:44

licess 发表于 2019-6-21 20:49
还是不行就很可能你系统上有问题,也没其他版本可以试了

这个 OK 了!

phper 发表于 2019-8-22 20:37:06

cyccc 发表于 2019-7-30 18:46
你看下 ls /lib/systemd/system/rc*    有没有rc.local.service

如果有,


谢谢上面 军哥的方法已经OK了
页: [1]
查看完整版本: Ubuntu 18.04.2 LTS lnmp1.6 服务器重启后 nginx不能启动