Steps

Logging In

ssh -i key.pem ubuntu@YOUR_IP use this to login to your machine

Scripts

Initialising Server Dependencies

  1. After loggin in type nano [script.sh](<http://script.sh>) and paste the following contents
# Update package list
sudo apt update

# Install software-properties-common with automatic confirmation
sudo apt install -y software-properties-common

# Add the deadsnakes PPA repository
sudo add-apt-repository ppa:deadsnakes/ppa

# Update package list again after adding the new repository
sudo apt update

# Install Python 3.10 with automatic confirmation
sudo apt install -y python3.10

# Install Nginx with automatic confirmation
sudo apt install -y nginx

# Install wget with automatic confirmation
sudo apt install -y wget

#Install pip
sudo apt install -y python3-pip

#Install venv
sudo apt install -y python3-venv

# Start Nginx service
sudo systemctl start nginx

# Enable Nginx to start on boot
sudo systemctl enable nginx

  1. Run chmod +x script.ah to change the file permission to allow execution
  2. Run ./script.sh to run the file

Initialising NGINX

  1. After running the above script, create a file called config.sh using nano
    1. nano config.sh
    2. You can give any name to this, I just named it config
  2. Copy the following contents
PUBLIC_IP=$(wget -qO- <http://checkip.amazonaws.com>)

if [ -z "$PUBLIC_IP" ]; then
    echo "Failed to retrieve public IP address."
    exit 1
fi

# Create the Nginx configuration file content with the public IP
NGINX_CONFIG="server {
    listen 80;
    listen [::]:80;
    server_name $PUBLIC_IP;
        
    location / {
        proxy_pass <http://127.0.0.1:5000>;
        include proxy_params;
    }
}"

# Write the configuration to /etc/nginx/sites-enabled/default
echo "$NGINX_CONFIG" | sudo tee /etc/nginx/sites-enabled/"$PUBLIC_IP" > /dev/null

# Restart Nginx to apply the changes
sudo systemctl restart nginx