我面临这个错误,
nginx:[emerg] /etc/nginx/conf.d/default.conf:1 中不允许使用“worker_processes”指令
Docker 文件:
FROM artifactorycloud.ual.com/v-docker/node:16 AS builder
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build --configuration=development
FROM artifactorycloud.ual.com/v-docker/nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html
# Copy the nginx conf that we created to the container
COPY ./nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
这是我的 nginx.conf 文件:
更新配置文件服务器{监听 80;服务器名称 localhost;
root /usr/share/nginx/html;
index index.html index.htm;
include /etc/nginx/mime.types;
gzip on;
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
location / {
try_files $uri $uri/ /index.html;
}
location /ui/health {
access_log off;
add_header 'Content-Type' 'text/plain';
return 200 "Healthy\n";
}
}
原始 nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html index.htm;
include /etc/nginx/mime.types;
gzip on;
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
location / {
try_files $uri $uri/ /index.html;
}
location /ui/health {
access_log off;
add_header 'Content-Type' 'text/plain';
return 200 "Healthy\n";
}
}
}
有人能帮助我解决我错的地方吗?
答案1
这实际上不是您的main
nginx.conf
文件,而是您(或您的某个)网站的配置文件。
接受该指令的主要配置文件worker_process
位于/etc/nginx/nginx.conf
。
您的http
和events
指令在下也将不起作用/etc/nginx/conf.d/default.conf
。
默认的 nginx.conf 文件已经有这些指令,并且工作进程设置为自动:
worker_processes auto;
从您的网站配置文件中删除 http、events 和 worker_processes,并在主nginx.conf
文件内调整这些设置。