nginx全新安assembly置

我刚刚在我的服务器上安装了nginx, 现在我可以看到

ps aux | grep nginx 

它正在执行与我的用户(这是正确的,或者它应该与根运行? 无论如何,我无法做任何事情,不能阻止它,因为

 nginx -s stop 

输出:

 nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied) 2017/05/02 04:03:34 [warn] 2482#2482: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:2 2017/05/02 04:03:34 [notice] 2482#2482: signal process started 2017/05/02 04:03:34 [error] 2482#2482: open() "/var/run/nginx.pid" failed (2: No such file or directory) 

我一直在search这些警告和错误,但我不能真正理解它们。 有人可以解释一下:

  • 日志文件警告和.pid文件错误的含义
  • 如果nginx应该与我的用户或根(或其他)运行,

更新:

我使用的是Ubuntu 16.04(xenial),我已经安装了nginx

 deb http://nginx.org/packages/ubuntu/ xenial nginx 

到sources.list然后

 sudo apt-get install nginx 

更新2

试图用“sudo”来阻止nginx仍然会导致错误:

 nginx: [error] open() "/var/run/nginx.pid" failed (2: No such file or directory) 

无论如何,我也为什么困惑

 ps aux | grep nginx 

显示了在我的用户下运行的进程(但是不可能使用PID来终止它,并且每次运行命令时PID都不同)

更新3

赛跑

 nginx -t 

输出:

 nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied) 2017/05/02 15:32:53 [warn] 8535#8535: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:2 nginx: the configuration file /etc/nginx/nginx.conf syntax is ok 2017/05/02 15:32:53 [emerg] 8535#8535: open() "/var/run/nginx.pid" failed (13: Permission denied) nginx: configuration file /etc/nginx/nginx.conf test failed 

当你想启动或停止nginx守护进程时,你需要有root权限。 以普通用户身份运行命令将不起作用。

这对Linux中的所有守护进程来说都是非常标准的。

你如何安装nginx? 也许你应该尝试使用版本库软件包进行良好的默认configuration,否则你可以阅读nginx手册来获取更多信息。 对我来说,你的问题只是错误configuration的服务器。 你能指定你使用的发行版吗? cat /etc/issue

您需要以root身份运行Nginx主进程。 然后,您可以configurationNginx以您喜欢的用户或组的身份运行工作进程 – 这是错误消息所指的内容。

具体怎么做取决于你没有指定的操作系统。 现在你知道问题是什么,你可以使用谷歌解决细节。

Nginx作为一个守护进程运行,应该作为一个服务而不是一个用户进程来pipe理。 在Ubuntu下,你可以使用service命令:

  • sudo service nginx start
  • sudo service nginx stop停止nginx
  • sudo service nginx restart然后重新启动nginx
  • sudo service nginx reload告诉nginx重新加载其configuration文件而不停止服务

编辑:并获得状态, sudo service nginx status