Nginx 权限 13

0 nginx

我在一个共享主机上,有权继承 nginx 根安装并覆盖它的配置文件(注意:我不想在我的主目录中编译我自己的 nginx)。

我写了一个启动/重新加载/停止脚本,它运行良好,但是我不断收到以下错误

启动脚本

#!/bin/bash

# Set this to your nginx configuration file and PID

CONFIG=~/nginx/nginx.conf
PIDFILE=~/nginx/nginx.pid


# Do not change anything below unless you know what you do

DAEMON=/usr/local/nginx/sbin/nginx
NAME="nginx"
PATH=/sbin:/bin:/usr/sbin:/usr/bin
OPTS="-c $CONFIG"

...
Run Code Online (Sandbox Code Playgroud)

我的配置:

worker_processes  4;

error_log  /home/myusername/nginx/error.log;
pid        /home/myusername/nginx/nginx.pid;

events {
    worker_connections  8192;
    multi_accept on;
    use epoll;
}

http {
    error_log /home/myusername/nginx/error.log;
    access_log /home/myusername/nginx/access.log;
    server_names_hash_max_size 8192;
    server_names_hash_bucket_size 128;
    include       /etc/nginx/mime.types;
    underscores_in_headers on;
...
Run Code Online (Sandbox Code Playgroud)

错误:

Reloading nginx configuration: [alert]: could not open error log file: open() "/usr/local/nginx/logs/error.log" failed (13: Permission denied)
nginx.
Run Code Online (Sandbox Code Playgroud)

所以它似乎没有正确读取我的错误和访问日志位置,我该如何解决这个问题,谢谢!

小智 5

NGINX 在读取您的配置文件之前搜索内置错误日志位置。

您可以在这里找到它:http : //wiki.nginx.org/CoreModule 在 error_log 部分下。

“还要注意,从 0.7.53 版本开始,nginx 将使用编译好的默认错误日志位置,直到它读取了配置文件。如果运行 nginx 的用户没有对该日志位置的写权限,nginx 将引发一个像这样警报:

[警报]:无法打开错误日志文件:open() "/var/log/nginx/error.log" failed (13: Permission denied) "