Skip to content

Commit

Permalink
Feito funcionamento de estáticos via Nginx na porta 80
Browse files Browse the repository at this point in the history
parte de #7
  • Loading branch information
renzo authored and renzon committed Aug 8, 2024
1 parent 919c60d commit 58b8555
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ venv.bak/
#Postgres local volume
docker/.pgdata/

# static files generated by collect static from django
docker/staticfiles/


# Spyder project settings
.spyderproject
Expand Down
4 changes: 3 additions & 1 deletion backend/devpro/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@
# Application definition

INSTALLED_APPS = [
'devpro.base',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'devpro.base',

]

MIDDLEWARE = [
Expand Down Expand Up @@ -116,6 +117,7 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.0/howto/static-files/

STATIC_ROOT = BASE_DIR.parent/'docker/staticfiles/static'
STATIC_URL = 'static/'

# Default primary key field type
Expand Down
9 changes: 9 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
version: "3.3"

services:
nginx:
container_name: nginx
image: nginx:1.27.0
volumes:
- ./staticfiles:/usr/share/nginx/html
- ./nginx.conf:/etc/nginx/nginx.conf:ro
ports:
- 80:80
network_mode: host
database:
container_name: postgres
image: postgres:16.3
Expand Down
24 changes: 24 additions & 0 deletions docker/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
events {
# configuration of connection processing
}

http {
server {
listen 80;
server_name localhost;

location / {
proxy_pass http://localhost:8000; # Porta onde o seu aplicativo Django está rodando
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 /static/ {
alias /usr/share/nginx/html/static/; # Substitua pelo caminho do seu diretório STATIC_ROOT
include /etc/nginx/mime.types;
}

}
}

0 comments on commit 58b8555

Please sign in to comment.