Nginx 目录(21:是目录)

Nginx 目录(21:是目录)

我正在尝试在 AWS Linux 上进行配置nginx。我可以让它在一个站点上运行,但当我尝试添加另一个站点时,我不断收到以下错误:

nginx: [crit] pread() "/home/ec2-user/public/sites/example.com" failed (21: Is a directory)

这是我的nginx.conf

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    include             /home/ec2-user/public/sites/*;
    default_type        application/octet-stream;

    include /etc/nginx/conf.d/*.conf;

    index   index.html index.htm;

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  localhost example.es www.example.es;
        root         /home/ec2-user/public/sites/es-example;

        location / {
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

    server {
        listen       80;
        listen       [::]:80;        
        server_name  example.com www.example.com;
        root         /home/ec2-user/public/sites/en-example;

        location / {
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
}

目录example.comexample.es均有index.html。两个目录的权限如下。

-rwxr-xr-x 1 ec2-user ec2-user

有什么想法吗?谢谢!

答案1

问题出在这一行:

include             /home/ec2-user/public/sites/*;

上述指令由 nginx 用于加载/包含其他配置选项。只有适当的 nginx 配置文件才应放在

/home/ec2-user/public/sites/

如果你也把目录或网站(内容)文件放在那里,nginx 将无法包含它们。请查看 nginx 文档

http://nginx.org/en/docs/ngx_core_module.html#include

答案2

通过确保以下行未被注释,也可以解决此问题:

pid        logs/nginx.pid;

答案3

在我的例子中,发生了相同的错误,但我发现 /etc/nginx/sites-enabled/ 目录中有一个目录...我只需将其删除即可解决问题。但这并不能阻止 nginx 工作,它只是不会读取任何内容,因为它没有任何 .conf 文件可读取。

相关内容