To run this project locally, ensure you have Docker Desktop installed. Then:
- Clone the repository and navigate to the
my_websitedirectory. - SMTP server for generating OTP. I have used gmail's SMTP server for my localhost (You may go through this video for reference): https://youtu.be/y5IasMFYdBc?si=HQLDn9fRT3lCX-1D
- Create a .env file in ".upload-service" directory and add the following value based on your SMTP server configurations.
# .env file for SMTP configuration SMTP_HOST=smtp.gmail.com SMTP_PORT=465 SMTP_SECURE=true SMTP_USER=<your_email_id>@gmail.com SMTP_PASS=<generated_smtp_password> ADMIN_EMAILID=<email_id_where_you_would_receive_OTP_for_authentication>
- Execute the initial build command:
Now, you should be able to access the frontend through the localhost.
make initial_build PROD=true
make down: Stop the running containers.make up PROD=true: Start the containers.make rebuild PROD=true: Stop, rebuild, and restart the containers.make destroy_project: Stop and remove all containers and associated data. |
To deploy your website with an SSL certificate, follow these steps:
-
Deploy your code on a server: Also note its public IP address.
-
Acquire a Domain Name: Obtain a registered domain name from a trusted provider.
-
Frontend Configuration (
frontend/script.js):- Update the value of
const PUBLIC_IP. - Set
PROD = truewithin this file.
- Update the value of
-
Nginx Configuration (
nginx/nginx.conf):- Initially, update the
server_namedirective to include your exact domain name(s) (e.g.,yourdomain.com www.yourdomain.com).
- Initially, update the
-
DNS Mapping: Map your domain name(s) to your server's public IP address using A/AAAA records in your DNS settings.
-
Initial Project Build (HTTP): Build your project using the provided
Makefile. Please note that your website will initially be accessible via HTTP (port 80).make initial_build PROD=true
-
Generate SSL Certificate:
- Initially, the "my-website-nginx" container will fail because it is mounting the certificate from the local directory, and it is not present. So, turn off the container:
docker stop my-website-nginx
- Run certbot in standalone mode:
docker run -it --rm \ -v ./data/certbot/conf:/etc/letsencrypt \ -v ./data/certbot/www:/var/www/certbot \ --publish 80:80 \ --publish 443:443 \ certbot/certbot certonly \ --standalone \ -d <domain_name> \ -m <your_email@example.com> \ --agree-tos \ --no-eff-email
- Start Nginx Container (after Certbot succeeds)
docker start my-website-nginx
- Initially, the "my-website-nginx" container will fail because it is mounting the certificate from the local directory, and it is not present. So, turn off the container:
-
Update Nginx Configuration for Production:
- Replace the content of your
nginx/nginx.confwith the production-ready configuration fromnginx_for_prod/nginx.conf. - Replace the content of your
nginx/Dockerfilewith the production-ready Dockerfile fromnginx_for_prod/Dockerfile. - Replace <domain_name> in both the above files with your actual domain name ex: ninad.meverse.in.
- Replace <public_IP_address> in nginx/nginx.conf with your actual public IP address
- Replace the content of your
-
Final Project Rebuild: Rebuild your Docker project to apply the updated Nginx configuration and activate HTTPS.
make rebuild PROD=true
-
Change the script permission:
chmod +x update_script.sh chmod +x restart_mongodb.sh
-
Commit all the changes locally, DO NOT PUSH
-
To make sure git pull does not modify local changes:
git update-index --skip-worktree nginx/nginx.conf
git update-index --skip-worktree nginx/Dockerfile- Scheduling update_website.sh to pull new changes every day at 12 AM:
- Run
crontab -eto open crontab - Add following line to the file
0 0 * * * <path_to_my_website>/update_website.sh <path_to_my_website> - Add following line to the file
30 * * * * <path_to_my_website>/restart_mongodb.sh <path_to_my_website> - Save and close
- Run