以非root用户身份运行nginx

我遵循这个过程在我的Ubuntu 10.04 Lucid Server上安装nginx http://library.linode.com/web-servers/nginx/installation/ubuntu-10.04-lucid

创build一个启动脚本启动nginx,然后调用/etc/init.d/nginx start之后,我迷了路。 当我这样做,我得到了以下错误:

Starting nginx_main: Starting /opt/nginx/sbin/nginx... nginx: [alert] could not open error log file: open() "/opt/nginx/logs/error.log" failed (13: Permission denied) 2012/03/16 18:17:27 [emerg] 859#0: open() "/opt/nginx/logs/access.log" failed (13: Permission denied) 

我可以运行它的唯一方法是如果我使用sudo ,它以root身份运行进程,这是我不想要的。

我已经find了整个目录( chown -R nginx:nginx /opt/nginx ),而且我还把chmod -R 755作为目录。

按照CS3的build议添加user指令也给了我这个错误,但是增加了一行。

 Starting nginx_main: Starting /opt/nginx/sbin/nginx... nginx: [alert] could not open error log file: open() "/opt/nginx/logs/error.log" failed (13: Permission denied) 2012/03/16 18:48:34 [warn] 1606#0: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /opt/nginx/conf/nginx.conf:2 2012/03/16 18:48:34 [emerg] 1606#0: open() "/opt/nginx/logs/access.log" failed (13: Permission denied) 

有任何想法吗?

首先,init脚本应该运行

 sudo /etc/init.d/name 

当你没有以root身份login时(当login用户启用了sudo)

其次,当你运行sudo /etc/init.d/nginx start ==>时,它会以root用户和工作进程的forms触发你在nginx.conf用户指令中指定的用户(例如www-data)

你可以确认你的所有进程在nginx下运行时是否以root身份运行sudo /etc/init.d/nginx start?

 ps aux | grep [n]ginx 

例如。

在这里输入图像描述

build议:Ubuntu 10.04 LTS拥有来自nginx团队的优秀ubuntu软件包支持。 那么,如果你不需要在nginx里面定制模块,为什么还要从源代码安装呢?

在这里咨询

二进制包已经有了非常需要的模块

 nginx version: nginx/1.0.12 TLS SNI support enabled configure arguments: --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --lock-path=/var/lock/nginx.lock --pid-path=/var/run/nginx.pid --with-debug --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_realip_module --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-http_xslt_module --with-ipv6 --with-sha1=/usr/include/openssl --with-md5=/usr/include/openssl --with-mail --with-mail_ssl_module --add-module=/build/buildd/nginx-1.0.12/debian/modules/nginx-echo --add-module=/build/buildd/nginx-1.0.12/debian/modules/nginx-upstream-fair 

在nginx.conf中添加用户指令

参考: http : //wiki.nginx.org/CoreModule#user

我的这个5 kopek

nginx -V 2>&1 | sed 's/ --/\n--/g' | grep path

..会让你所有其他pathes,你应该覆盖自定义提供的configuration或“-g”选项。

在我的情况下,在我的nginx.conf文件中没有引用文件:

error_log /var/log/nginx/error.log警告;

成为:error_log警告;

所以我意外地删除了/var/log/nginx/error.log引用了一个权限被拒绝的错误信息。