[英]How to overwrite nginx default config with docker file?
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.
我有一个使用React Router的应用程序,我为它做了docker镜像,并且我正在使用Nginx服务器,并且它正在工作。 But, when i want to refresh a page i am giving nginx 404 error.
但是,当我想刷新页面时,我给出了nginx 404错误。 I know that i need to overwrite nginx config file to make it works, but dont know why it doesnt work.
我知道我需要覆盖nginx配置文件以使其起作用,但不知道为什么它不起作用。 I tryed just to do some kind of redirect into nginx.conf just to see if it overides default.conf but it doesnt work.
我只是尝试将某种重定向重定向到nginx.conf中,只是为了查看它是否覆盖了default.conf,但它不起作用。 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;
}
EDIT: 编辑:
And how to check what config file is running? 以及如何检查正在运行的配置文件?
I believe you should use 我相信你应该使用
COPY ./nginx/default.conf /etc/nginx/nginx.conf
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/
如果你想组织的事情
conf.d/
,加include /etc/nginx/conf.d/*
在/etc/nginx/nginx.conf
中添加的东西之前conf.d/
Complete config file: 完整的配置文件:
worker_processes 4;
events {
worker_connections 1024;
}
http {
server {
listen 80 default;
server_name localhost;
return 301 https://www.google.com$request_uri;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.