Skip to content

Commit

Permalink
Add Nginx configuration and Dockerfile updates for static file handling
Browse files Browse the repository at this point in the history
The commit includes a new Nginx configuration file to effectively manage static and media files. Dockerfile is updated to create and set the right permissions for media and static directories, and to collect static files. Also, Dockerfile is now set up to use the new Nginx configuration for better consistency and easier deployment.
  • Loading branch information
scaphilo committed Apr 6, 2024
1 parent 88d9b4b commit 484a6a5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
16 changes: 15 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ RUN apt-get update && apt-get install -y \

WORKDIR /usr/src/app


# Create media and static directories
RUN mkdir -p /usr/src/app/media /usr/src/app/static

# Change the owner of these directories to www-data
RUN chown -R www-data:www-data /usr/src/app/media /usr/src/app/static


COPY settings /usr/src/app
COPY dashboard.py /usr/src/app
COPY manage.py /usr/src/app
Expand All @@ -37,8 +45,14 @@ RUN chmod 755 /usr/bin/fop-2.9/fop/fop
ENV JAVA_HOME /usr/lib/jvm/java-17-openjdk-amd64
ENV DJANGO_SETTINGS_MODULE=settings.production_docker_postgres_settings

# Collect static files
RUN python manage.py collectstatic --no-input

# Copy the Nginx configuration file
COPY nginx.conf /etc/nginx/sites-enabled/default

# Port to expose
EXPOSE 8000
EXPOSE 80

# Command to run the Django development server
CMD python manage.py migrate && gunicorn --bind :8000 wsgi
19 changes: 19 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
server {
listen 80;
server_name localhost;

location /static/ {
alias /usr/src/app/staticfiles/;
}

location /media/ {
alias /usr/src/app/mediafiles/;
}

location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}

0 comments on commit 484a6a5

Please sign in to comment.