Skip to content

Commit

Permalink
Merge pull request #26 from TheSecretOrganization/admin-page
Browse files Browse the repository at this point in the history
Fix - Redirected Django Admin Page
  • Loading branch information
antoineverin authored Aug 9, 2024
2 parents 03eb966 + a596b03 commit 1f0c539
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
5 changes: 2 additions & 3 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
# Nginx
HOSTNAME=
BASE_URL=
API_BASE_URL=

# Django
DEBUG=
SECRET_KEY=
DJANGO_SUPERUSER_USERNAME=
DJANGO_SUPERUSER_EMAIL=
DJANGO_SUPERUSER_PASSWORD=
DJANGO_ALLOWED_HOSTS=${HOSTNAME} ${BASE_URL} ${API_BASE_URL}
DJANGO_CSRF_TRUSTED_ORIGINS=${BASE_URL} ${API_BASE_URL}
DJANGO_ALLOWED_HOSTS=${HOSTNAME} ${BASE_URL}
DJANGO_CSRF_TRUSTED_ORIGINS=${BASE_URL}

# Database
POSTGRES_DB=
Expand Down
4 changes: 2 additions & 2 deletions django/src/ft_transcendence/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
router = routers.DefaultRouter()

urlpatterns = [
path('/', include(router.urls)),
path('admin/', admin.site.urls),
path('api/', include(router.urls)),
path('api/pages/<str:page_name>/', PagesView.as_view(), name='pages'),
path('pages/<str:page_name>/', PagesView.as_view(), name='pages'),
]
9 changes: 7 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ services:

nginx:
container_name: nginx
build: nginx
build:
context: nginx
args:
HOSTNAME: ${HOSTNAME}
ports:
- 8080:80
init: true
Expand All @@ -40,11 +43,13 @@ services:
- nginx-src:/usr/share/nginx
- static-files:/static
- media-files:/media
env_file:
- .env
depends_on:
django:
condition: service_healthy
healthcheck:
test: ["CMD-SHELL", "curl -o /dev/null -s -w '%{http_code}' http://localhost/ | grep 200 || exit 1"]
test: ["CMD-SHELL", "curl -o /dev/null -s -w '%{http_code}' ${BASE_URL} | grep 200 || exit 1"]
interval: 2s
timeout: 2s
retries: 5
Expand Down
6 changes: 5 additions & 1 deletion nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
FROM nginx:1.26.1

ARG HOSTNAME
ENV HOSTNAME=${HOSTNAME}

EXPOSE 80
VOLUME [ "/usr/share/nginx" ]

RUN apt update && apt upgrade -y

COPY conf/nginx.conf /etc/nginx/conf.d/default.conf
COPY conf/default.conf.template /etc/nginx/conf.d/default.conf.template
RUN envsubst '${HOSTNAME}' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf

CMD [ "nginx", "-g", "daemon off;" ]
16 changes: 10 additions & 6 deletions nginx/conf/nginx.conf → nginx/conf/default.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,37 @@ upstream django {

server {
listen 80;
server_name ft_transcendence;
server_name ${HOSTNAME};

# Serve the frontend
root /usr/share/nginx;
index index.html;

location / {
try_files $uri $uri/ /index.html =404;
}

# Serve static files for Django
location /static/ {
alias /static/;
expires 30d;
access_log off;
}

# Serve media files for Django
location /media/ {
alias /media/;
expires 30d;
access_log off;
}

# Proxy requests to the Django backend
location /api/ {
proxy_pass http://django;
proxy_pass http://django/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

location /admin/ {
proxy_pass http://django/admin/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Expand Down

0 comments on commit 1f0c539

Please sign in to comment.