Skip to content

ninadrathod/my_website

Repository files navigation

Setting up the website

Local Setup

To run this project locally, ensure you have Docker Desktop installed. Then:

  1. Clone the repository and navigate to the my_website directory.
  2. 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
  3. 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>
  4. Execute the initial build command:
    make initial_build PROD=true
    Now, you should be able to access the frontend through the localhost.

Additional make Commands

  • 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. |

Deploying Your Website with SSL/HTTPS

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 = true within this file.
  • Nginx Configuration (nginx/nginx.conf):

    • Initially, update the server_name directive to include your exact domain name(s) (e.g., yourdomain.com www.yourdomain.com).
  • 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
  • Update Nginx Configuration for Production:

    • Replace the content of your nginx/nginx.conf with the production-ready configuration from nginx_for_prod/nginx.conf.
    • Replace the content of your nginx/Dockerfile with the production-ready Dockerfile from nginx_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
  • 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 -e to 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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published