gpt4 book ai didi

docker - nginx: [emerg] open() "/run/nginx.pid"failed (13: Permission denied)

转载 作者:行者123 更新时间:2023-12-05 00:45:14 24 4
gpt4 key购买 nike

我有以下 Dockerfile,我已将其设置为使用新用户,而不是为我的 nginx 服务器使用 root。 nginx 服务器建立在 Redhat UBI 镜像之上。图像构建良好,但是当我运行容器时出现以下错误: nginx: [nginx: [emerg] open() "/run/nginx.pid"failed (13: Permission denied)

下面是我的 dockerfile。

USER root
RUN microdnf --setopt=tsflags=nodocs install -y nginx procps shadow-utils net-tools ca-certificates dirmngr gnupg wget vim\
&& microdnf clean all \
&& rpm -q procps-ng

ENV NGINX_USER="api-gatway" \
NGINXR_UID="8987" \
NGINX_GROUP="api-gatway" \
NGINX_GID="8987"

RUN set -ex; \
groupadd -r --gid "$NGINX_GID" "$NGINX_GROUP"; \
useradd -r --uid "$NGINXR_UID" --gid "$NGINX_GID" "$NGINX_USER"


COPY nginx.conf /etc/nginx/nginx.conf

RUN mkdir -p /var/lib/nginx/tmp /var/log/nginx \
&& chown -R api-gatway:api-gatway /var/lib/nginx /var/log/nginx \
&& chmod -R 755 /var/lib/nginx /var/log/nginx

EXPOSE 1080
USER api-gatway
CMD ["nginx", "-g", "daemon off;"]

当我构建镜像时,它构建时没有任何错误,但是当我使用 helm 在我的 K8 集群上部署时,它给了我以下错误。

nginx: [emerg] open() "/run/nginx.pid" failed (13: Permission denied)

这是我设置的 nginx.conf 文件

worker_processes  1;
error_log /tmp/error.log;
pid /run/nginx.pid;

events {
worker_connections 1024;
}
http {
server {
listen 1080;
server_name localhost 127.0.0.1;
access_log /tmp/access.log;
client_max_body_size 0;
set $allowOriginSite *;
proxy_pass_request_headers on;
proxy_pass_header Set-Cookie;
# External settings, do not remove

#ENV_ACCESS_LOG
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass_header Set-Cookie;
proxy_set_header X-Forwarded-Proto $scheme;

location /search/ {
proxy_pass http://*******-svc:8983/***/;
}
location /auth/ {
proxy_pass http://********:8080;
}
location /mapbox {
rewrite ^/mapbox(.*)https://****$1 break;
}
}
}

如何修复 nginx: [emerg] open() "/var/run/nginx.pid"failed (13: Permission denied) 我在配置中做错了什么?

最佳答案

更新

为了修复我的“/var/run/nginx.pid”权限被拒绝错误。

我必须在我的 dockerfile 中添加 nginx.pid 权限错误才能让新用户工作。

以下是我在 dockerfile 中所做的更改

RUN touch /run/nginx.pid \
&& chown -R api-gatway:api-gatway /run/nginx.pid /cache/nginx

关于docker - nginx: [emerg] open() "/run/nginx.pid"failed (13: Permission denied),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64393237/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com