【问题标题】:nginx: [emerg] open() "/var/run/nginx.pid" failed (13: Permission denied)nginx: [emerg] open() "/var/run/nginx.pid" 失败 (13: Permission denied)
【发布时间】:2019-12-17 00:35:34
【问题描述】:

我有以下 docker 文件

FROM grafana/grafana
EXPOSE 8080 8080
COPY config /config
COPY start-nginx-grafana.sh /start-nginx-grafana.sh
USER root
RUN apt-get update && apt-get install -y nginx
RUN chown -R grafana:grafana /etc/nginx/nginx.conf /var/log/nginx /var/lib/nginx /start-nginx-grafana.sh
RUN chmod +x /start-nginx-grafana.sh /etc/nginx/nginx.conf /var/log/nginx /var/lib/nginx
USER grafana
RUN cp /config/nginx.conf /etc/nginx/nginx.conf
ENTRYPOINT [ "/start-nginx-grafana.sh" ]

当我构建它并尝试运行一个容器时,它运行没有问题,但我无法访问 Nginx 代理后面的网站,所以我检查了 docker 日志,我发现了

nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1
nginx: [emerg] open() "/var/run/nginx.pid" failed (13: Permission denied)

我的 Nginx 配置如下

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


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

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
    server {
        listen 3001;
        root /usr/share/nginx/www;
        index index.html index.htm;

        location / {
                proxy_pass                            http://localhost:3000/;
                proxy_set_header Host                 $http_host;
                proxy_set_header X-Real-IP            $remote_addr;
                proxy_set_header X-Forwarded-For      $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto    $scheme;
                proxy_set_header X-WEBAUTH-USER       "";
                }
        }
    server {
        listen 8080;
        location / {
                proxy_pass                            http://localhost:3000/;
                proxy_set_header Host                 $http_host;
                proxy_set_header X-Real-IP            $remote_addr;
                proxy_set_header X-Forwarded-For      $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto    $scheme;
                proxy_set_header X-WEBAUTH-USER       "guest";
        }
    }
}

我该如何修复 nginx: [emerg] open() "/var/run/nginx.pid" failed (13: Permission denied) 以及我做错了什么。

【问题讨论】:

  • 我通常会在单独的容器中运行 Grafana 和 Nginx,这样可以避免这个特定问题。 (并且您应该能够在启动时立即注意到 Nginx 容器出现故障而不会影响 Grafana 容器。)
  • 您可以尝试将 nginx.conf 中的 User 更改为 grafana,然后将 nginx 服务器也作为 grafana 运行。可能会奏效。

标签: docker nginx grafana


【解决方案1】:

您使用用户 grafana 运行所有进程

警告状态:nginx 主进程不是超级用户。

grafana 用户无权访问文件/var/run/nginx.pid

我建议你从你的Dockerfile 中删除USER grafana 并在你的脚本中使用命令运行你的grafana

runuser -l grafana -c "...."

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-31
    • 2021-11-08
    • 2018-11-02
    • 2019-06-18
    • 2017-06-18
    • 2013-08-31
    • 2015-05-25
    • 2021-05-16
    相关资源
    最近更新 更多