如何使用Docker文件覆盖Nginx默认配置? [英] How to overwrite nginx default config with docker file?
问题描述
我知道已经有人问过这个问题或类似的问题,但是我已经与之抗争了一段时间.我有一个使用反应路由器的应用程序,我为它做了docker镜像,并且我正在使用nginx服务器,并且它正在工作.但是,当我要刷新页面时,我给出了nginx 404错误.我知道我需要覆盖nginx配置文件以使其起作用,但是不知道为什么它不起作用.我只是尝试将某种重定向重定向到nginx.conf,只是为了查看它是否覆盖default.conf,但它不起作用.这是我的文件:
I know this question or similar one was asked already, but i am fighting with it for some time now. I have an app which is using react router, and i did docker image for it and i am using nginx server, and it is working. But, when i want to refresh a page i am giving nginx 404 error. I know that i need to overwrite nginx config file to make it works, but dont know why it doesnt work. I tryed just to do some kind of redirect into nginx.conf just to see if it overides default.conf but it doesnt work. This are my files:
Dockerfile:
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
nginx.conf
server {
listen 80 default;
server_name localhost;
return 301 https://www.google.com;
}
以及如何检查正在运行的配置文件?
And how to check what config file is running?
推荐答案
我相信您应该使用
COPY ./nginx/default.conf /etc/nginx/nginx.conf
如果要组织 conf.d/
中的内容,请在/etc/nginx/中添加
include/etc/nginx/conf.d/*
在添加 conf.d/
If you want to organise things in conf.d/
, add include /etc/nginx/conf.d/*
in /etc/nginx/nginx.conf
before adding things in 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;
}
}
这篇关于如何使用Docker文件覆盖Nginx默认配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!