Posts

Showing posts from July, 2024

Containerizing the app using Docker

Image
Docker is a powerful tool that makes it easy to run applications regardless of the machine you wrote the code on and the machine you want to run it on. It is widely used in practice as it allows developers to avoid the “But it runs on my laptop!” problem when their code doesn’t work. You will need to install Docker first from  this link  if you are working locally. This is how it works for (basic) python applications: Create a  requirements.txt  file Create a  Dockerfile  which contains instructions on how to build a Docker image Run  docker compose up  to create a container image, and run it Commit and push the image to a remote repo so others can run it exactly as you’ve configured! Docker images are commonly used in conjunction with Kubernetes, which is a service that manages containers. You will be briefly introduced to how you can setup this Django application to run using Docker. Before going into the technical stuff revolving around Docker, we just need to make one final change

Blocking Bad Bots - .htaccess (Apache2)

Block bad users based on their User-Agent string Sometimes your website can be attacked from different IP addresses and it is impossible to block all such users. If there is fixed user-agent in the request, you can block such access using the following rule: Block multiple bad User-Agents: <VirtualHost  XXX.140.234.34:80 >     ServerName www.example.us     LogLevel debug     ErrorLog /var/log/apache2/example.log     CustomLog /var/log/apache2/example.log combined     AddDefaultCharset utf-8     RewriteEngine On     # Block requests from Amazonbot - this rule sends a 403 Forbidden response ([F]) and stops processing further rewrite rules ([L]).     RewriteCond %{HTTP_USER_AGENT} Bytespider|ClaudeBot [NC]     RewriteRule ^ - [F,L]     RewriteCond %{SERVER_NAME} XXX.140.234.34     RewriteRule /(.*) http://www.example.us/$1 [R=301,L]     LimitRequestBody 5120000     WSGIDaemonProcess www.example.us processes=10 threads=10 maximum-requests=1000 display- name =%{ GROUP }     W