nginx 无法为 readonlyRootfilesystem 启动

问题描述 投票:0回答:1

我正在尝试为 readonlyRootfilesystem 配置 nginx,但默认情况下它会在 /var/lib/nginx 、 /var/log/nginx 、 /etc/nginx 位置创建一些目录

enter image description here

我正在寻找 nginx 在不同的位置创建这些目录,例如 /tmp 而不是 /var/lib ,因为 /tmp 在设置中安装为不同的卷,我当前将文件系统设置为只读,并且何时文件系统设置为只读 nginx 失败并出现错误

无法打开错误日志文件:open()“/var/log/nginx/error.log” 失败(30:只读文件系统)

/var/log 目录的权限

enter image description here

enter image description here

这里是 /etc/nginx/nginx.conf

user  www-data;
worker_processes  auto;

pid        /tmp/nginx/nginx.pid;

error_log   /tmp/log/nginx/error.log warn;

include /etc/nginx/modules-enabled/*.conf;



events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    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  /tmp/log/nginx/access.log  main;


    ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    sendfile on;
    tcp_nopush on;
    types_hash_max_size 2048;

    keepalive_timeout  65;

    gzip  on;

    # Temporary directories for "readonlyfilesystem"
    client_body_temp_path /tmp/log/nginx/nginx-client-body;
    proxy_temp_path       /tmp/log/nginx/nginx-proxy;
    fastcgi_temp_path     /tmp/log/nginx/nginx-fastcgi;
    uwsgi_temp_path       /tmp/log/nginx/nginx-uwsgi;
    scgi_temp_path        /tmp/log/nginx/nginx-scgi;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;

}

这是流程信息

ps -ef | grep nginx
root@929b5a6a057e:/app# ps -ef | grep nginx
root         9     1  0 05:30 ?        00:00:00 nginx: master process /usr/sbin/nginx -g daemon off;
www-data    11     9  0 05:30 ?        00:00:00 nginx: worker process
www-data    12     9  0 05:30 ?        00:00:00 nginx: worker process
www-data    13     9  0 05:30 ?        00:00:00 nginx: worker process
www-data    14     9  0 05:30 ?        00:00:00 nginx: worker process
www-data    15     9  0 05:30 ?        00:00:00 nginx: worker process
www-data    16     9  0 05:30 ?        00:00:00 nginx: worker process
www-data    17     9  0 05:30 ?        00:00:00 nginx: worker process

这是我的站点配置文件

enter image description here

日志位置

enter image description here

即使我更改了 nginx.conf 中的日志位置,但仍然

nginx -v
显示为
/var/log/nginx

enter image description here

如何配置 nginx 以使用只读文件系统运行?

django nginx nginx-config
1个回答
0
投票

检查哪个用户正在运行 Nginx。默认情况下,您可以在

/etc/nginx/nginx.conf
文件中找到它,特别是通过查找
user
指令 (http://nginx.org/en/docs/ngx_core_module.html#user)。之后,确保用户有权读取/写入您需要的路径。

您提到的错误 (

Could not open error log file: open() '/var/log/nginx/error.log' failed (30: Read-only file system)
) 可能会发生,因为由于 Nginx 无法写入指定路径,它会尝试将错误记录到其默认路径 (
/var/log/nginx/error.log
)。随着您所做的更改,这条路径可能不再存在。

© www.soinside.com 2019 - 2024. All rights reserved.