Reputation: 455
I have an app which is using React router, and I created a docker image for it. I am using nginx server and it works. But, refreshing a page gives me nginx 404 error. I know that I need to overwrite nginx config file to make it work, but don't know why it doesn't work.
I tried to add some kind of redirect to nginx.conf
just to see if it overrides default.conf
but it doesn't work. These are my files:
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:
And how to check what config file is running?
Upvotes: 3
Views: 29321
Reputation: 12129
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/
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;
}
}
Upvotes: 5