Skip to content

Commit

Permalink
added installation for if ssl certificate to nginx docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenaH84 committed Jun 14, 2024
1 parent d337428 commit 0aeb06d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
4 changes: 3 additions & 1 deletion docker-compose-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ services:
restart: always
ports:
- "8001:8001"
- "8002:8002"
- "80:80"
- "443:443"
depends_on:
- genie
- streamlit
command: /bin/bash -c "/renew-certs.sh && nginx -g 'daemon off;'"

streamlit:
image: ghcr.io/battmoteam/battmogui_streamlit:latest
Expand Down
16 changes: 14 additions & 2 deletions nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
FROM nginx:1.15.8

# Install Certbot and dependencies
RUN apt-get update && \
apt-get install -y certbot python3-certbot-nginx && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Remove default Nginx configuration files
RUN rm /etc/nginx/nginx.conf
COPY nginx.conf /etc/nginx/
RUN rm /etc/nginx/conf.d/default.conf
COPY project.conf /etc/nginx/conf.d/

# Copy your custom Nginx configuration
COPY nginx.conf /etc/nginx/

# Copy SSL certificate renewal script
COPY renew-certs.sh /renew-certs.sh
RUN chmod +x /renew-certs.sh
27 changes: 26 additions & 1 deletion nginx/project.conf
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,38 @@ server {
}

server {
listen 8002;
listen 80;
server_name app.batterymodel.com; # Replace with your domain name

location /.well-known/acme-challenge/ {
root /usr/share/nginx/html;
}

location / {
proxy_pass http://streamlit:80; # Assuming Streamlit runs on port 80 inside the container
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;
}
}

server {
listen 443 ssl;
server_name app.batterymodel.com;

ssl_certificate /etc/letsencrypt/live/app.batterymodel.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/app.batterymodel.com/privkey.pem;

location /.well-known/acme-challenge/ {
root /usr/share/nginx/html;
}

location / {
proxy_pass http://streamlit:80;
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;
}
}
7 changes: 7 additions & 0 deletions nginx/renew-certs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

# Run Certbot to obtain or renew certificates
certbot --nginx --non-interactive --agree-tos -d app.batterymodel.com

# Reload Nginx configuration to apply new certificates
nginx -s reload

0 comments on commit 0aeb06d

Please sign in to comment.