我有以下的 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) 问题以及我做错了什么。