如何用docker文件覆盖nginx默认配置?

2024-02-09

我有一个使用 React router 的应用程序,我为它创建了一个 docker 镜像。我正在使用 nginx 服务器并且它可以工作。但是,刷新页面会出现 nginx 404 错误。我知道我需要覆盖 nginx 配置文件才能使其工作,但不知道为什么它不起作用。

我尝试添加某种重定向nginx.conf只是为了看看它是否覆盖default.conf但它不起作用。这些是我的文件:

Dockerfile:

FROM nginx:alpine
COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/build /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

nginx.conf

server {
    listen       80 default;
    server_name  localhost;
    return 301 https://www.google.com;
 }

EDIT:

以及如何检查正在运行的配置文件?


我相信你应该使用

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

如果你想组织事情conf.d/, add include /etc/nginx/conf.d/* in /etc/nginx/nginx.conf在添加东西之前conf.d/

完整的配置文件:

worker_processes 4;

events {
    worker_connections  1024;
}

http {
  server {
      listen       80 default;
      server_name  localhost;
      return 301 https://www.google.com$request_uri;
  }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何用docker文件覆盖nginx默认配置? 的相关文章

随机推荐