Skip to content

Commit

Permalink
correção para usar o nginx como servidor em dev
Browse files Browse the repository at this point in the history
  • Loading branch information
HommerJr committed Jul 31, 2024
1 parent aa31bcc commit f35581b
Show file tree
Hide file tree
Showing 268 changed files with 64,511 additions and 20 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ COPY requirements.txt /app/
RUN pip install -r requirements.txt gunicorn

# Create SSL certificate
RUN mkdir -p /etc/ssl/certs /etc/ssl/private
RUN openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/selfsigned.key -out /etc/ssl/certs/selfsigned.crt -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=localhost"

# Copy the application code
Expand All @@ -44,4 +45,4 @@ RUN chown -R helios:helios /app

# Run the entrypoint script
RUN chmod +x /app/entrypoint.sh
ENTRYPOINT ["/app/entrypoint.sh"]
ENTRYPOINT ["/app/entrypoint.sh"]
18 changes: 13 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
version: '3.8'

services:
db:
image: postgres:16
Expand Down Expand Up @@ -27,11 +29,13 @@ services:
web:
build: .
env_file: .env
command: gunicorn --certfile=/etc/ssl/certs/selfsigned.crt --keyfile=/etc/ssl/private/selfsigned.key --bind 0.0.0.0:8000 helios.wsgi:application
command: gunicorn --bind 0.0.0.0:8000 helios.wsgi:application
volumes:
- .:/app
ports:
- "8000:8000"
- static_volume:/app/static
- certs:/etc/ssl
expose:
- "8000"
depends_on:
- db
- rabbitmq
Expand All @@ -55,15 +59,19 @@ services:
- "80:80"
- "443:443"
volumes:
- ./nginx:/etc/nginx/conf.d
- ./static:/usr/share/nginx/html/static
- ./nginx.conf:/etc/nginx/nginx.conf
- static_volume:/app/static
- certs:/etc/ssl
depends_on:
- web
networks:
- helios-network

volumes:
postgres_data:
certs:
static_volume:

networks:
helios-network:
driver: bridge
25 changes: 11 additions & 14 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# nginx.conf
worker_processes 1;

events {
Expand All @@ -10,45 +9,43 @@ http {
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log;

# SSL configuration
ssl_certificate /etc/letsencrypt/live/votacao.tadeujr.com.br/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/votacao.tadeujr.com.br/privkey.pem;

ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';

# Upstream Django/Gunicorn
# Define the upstream server
upstream django {
server unix:/app/app.sock;
server web:8000;
}

server {
listen 80;
server_name votacao.tadeujr.com.br;
server_name localhost;

location / {
rewrite ^ https://$host$request_uri? permanent;
return 301 https://$host$request_uri;
}
}

server {
listen 443 ssl;
server_name votacao.tadeujr.com.br;
server_name localhost;

ssl_certificate /etc/ssl/certs/selfsigned.crt;
ssl_certificate_key /etc/ssl/private/selfsigned.key;

location / {
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;
proxy_redirect off;
}

location /static/ {
Expand All @@ -59,4 +56,4 @@ http {
alias /app/media/;
}
}
}
}
Loading

0 comments on commit f35581b

Please sign in to comment.