【发布时间】:2022-01-01 15:34:52
【问题描述】:
我正在尝试找出这个 nginx 404 错误:
open() "/etc/nginx/html/index.html" 失败(2:没有那个文件或目录)
我正在使用带有 nginx 映像的 docker 和 docker-compose:
FROM nginx:1.21-alpine
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d
nginx.conf 文件如下所示:
upstream backend {
server backend:8000;
}
server {
listen 80;
server_name digibrain.co
www.digibrain.co;
location / {
root "/var/www/frontend";
}
location ~ \.(html|css|js)(.*)$ {
expires -1;
add_header Cache-Control no-store;
}
location /api/ {
proxy_pass http://backend;
proxy_set_header Host $http_host;
}
location /admin/ {
proxy_pass http://backend;
proxy_set_header Host $http_host;
}
location /static/ {
# In dev we need to proxy_pass to the backend.
# In prod we don't.
proxy_pass http://backend;
proxy_set_header Host $http_host;
alias /backend/static/;
}
}
当我转到localhost/api/ 时,后端工作正常,但前端不知何故坏了。想法?
【问题讨论】:
-
确保在您的 Nginx 配置(对于
server backend:8000)中使用正确的backendservice 名称(在docker-compose文件中使用的名称)。 -
后端工作正常。坏掉的是前端。
root "/var/www/frontend";