Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Bug/nginx 404 (#102)
Browse files Browse the repository at this point in the history
Fix `frontend` container sending 404 errors to non-root URL requests.
  • Loading branch information
mjaquiery authored Jun 26, 2023
1 parent 550f71b commit 9ee5890
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ RUN yarn build

FROM nginx:alpine
COPY --from=build /app/build /usr/share/nginx/html
COPY --from=build /app/nginx.conf.template /nginx.conf.template
COPY --from=build /app/nginx.conf.template /etc/nginx/conf.d/custom.conf

EXPOSE 80
CMD ["/bin/sh" , "-c" , "exec nginx -g 'daemon off;'"]
Expand Down
35 changes: 18 additions & 17 deletions frontend/nginx.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@
# Copyright (c) 2020-2023, The Chancellor, Masters and Scholars of the University
# of Oxford, and the 'Galvanalyser' Developers. All rights reserved.

worker_processes 1;

user nobody nogroup;
# 'user nobody nobody;' for systems with 'nobody' as a group instead
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

events { }

server {
listen 80;
server_name localhost;

http {
server {
listen 80;

# redirect 404 errors to homepage to avoid weird behaviour navigating directly to React-routed pages
error_page 404 =200 /;
client_max_body_size 100M;

# serve the static files
access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log debug;

location / {
root /usr/share/nginx/html;
root /usr/share/nginx/html;
index index.html index.htm;
# Serve index for any route that doesn't have a file extension (e.g. /devices)
# https://stackoverflow.com/a/45599233
try_files $uri $uri/ /index.html;
}

}
}
#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
2 changes: 1 addition & 1 deletion nginx-proxy/default
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
location /django_static/ {
alias /app/static/;
add_header Access-Control-Allow-Origin *;
}
}

0 comments on commit 9ee5890

Please sign in to comment.