Service Nginx不起作用

我在debian(jessie v8.2)系统上编译了源码nginx v1.9.6。 但是它不能按预期工作。 1.9.3版本没有任何问题。

当我尝试运行service nginx start我得到这个消息:

无法启动nginx.service:单元nginx.service加载失败:没有这样的文件或目录。

我使用这些参数进行configuration:

configuration参数:–prefix = / etc / nginx –sbin -path = / usr / sbin / nginx –conf -path = /etc/nginx/nginx.conf –error -log-path = / var / log / nginx / error.log –http-log-path = / var / log / nginx / access.log –pid-path = / var / run / nginx.pid –lock-path = / var / run / nginx。 lock –user = myuser –group = myuser –without -mail_pop3_module –without-mail_imap_module –without-mail_smtp_module –with-http_ssl_module –with-http_v2_module –with-file-aio –with-ipv6 – 没有-http_memcached_module

如果您收到错误消息Failed to start nginx.service: Unit nginx.service failed to load: No such file or directory. systemd没有findunit file

显然从源代码安装没有提供单位文件。 你需要像这样为nginx创build一个单元文件。

 [Unit] Description=The NGINX HTTP and reverse proxy server After=syslog.target network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/run/nginx.pid ExecStartPre=/usr/sbin/nginx -t ExecStart=/usr/sbin/nginx ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target 

调整安装path并将文件存储在/lib/systemd/system/nginx.service下。 您需要运行systemctl daemon-reload加载systemd。

看看官方文件了解更多信息。