以非root用户身份运行nginx

Joh*_*ohn 20 ubuntu permissions init.d ubuntu-10.04

我按照这个过程在我的 Ubuntu 10.04 Lucid 服务器上安装了 nginx http://library.linode.com/web-servers/nginx/installation/ubuntu-10.04-lucid

在创建 init 脚本以启动 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)
Run Code Online (Sandbox Code Playgroud)

我可以运行它的唯一方法是,如果我使用sudo它并且它将进程作为 运行root,这是我不想要的。

我已经创建chown了整个目录 ( chown -R nginx:nginx /opt/nginx) 并且我也拥有chmod -R 755了该目录。

user按照 CS3 的建议添加指令也会给我这个错误,但还有一行。

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)
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

kaj*_*aji 10

首先,应该运行init脚本

sudo /etc/init.d/name
Run Code Online (Sandbox Code Playgroud)

当您未以 root 身份登录时(当登录用户启用 sudo 时)

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

您能否在发出 sudo /etc/init.d/nginx start 时确认 nginx 下的所有进程是否都由 root 运行?

ps aux | grep [n]ginx
Run Code Online (Sandbox Code Playgroud)

例如。

在此处输入图片说明

建议: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
Run Code Online (Sandbox Code Playgroud)