【发布时间】: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 运行。可能会奏效。