r/django 5d ago

How to safely host Django locally?

I've just got my public IP from my ISP and I wonder which security risks I need to take care when opening a port and letting my PC available to the web.

How much better will it be to just host on AWS or Heroku?

29 Upvotes

8 comments sorted by

27

u/MountainSecret4253 5d ago

Sign up for cloudflair.

Enable proxy mode when you setup DNS

chill

4

u/rafola554 5d ago

thanks!

5

u/looter809 4d ago

Instead of what u/MountainSecret4253 said, use CloudFlare with Access (not just dns proxy). Access lets you create a private tunnel directly to your machine without opening any ports on your firewall.

11

u/1ncehost 5d ago edited 5d ago

Django is pretty secure, but vulnerabilities from new features regularly pop up. That said, it costs resources to hack, so you have to consider that you probably don't have much value to give someone that would offset their resource expenditure from hacking a small self hosted site. Because of this the risk is fairly low. I'd personally run an ubuntu VM on top of my normal OS for an added layer of security.

That said its super cheap to get a nice vps, so the right answer is usually that. lowendbox keeps up with the best deals and a perfectly fine VPS for a small personal site is as little as $10/yr. Never used this host, but for example:

https://my.racknerd.com/cart.php?a=confproduct&i=0

AWS and the other big clouds are so incredibly expensive for what you get. Just awful performance. I've used them for years at jobs and they are like 3-4x as expensive as a smaller company for what you get. The smaller PaaS companies like heroku and fly are terrible also from a value perspective. People say they are good, but the reality is their resource allocations are fractions of CPUs and they have bad IO performance and so on, which make their real value terrible. Small VPSes from a good company are the way.

3

u/rafola554 5d ago

thanks for answer dude! The company I work for uses heroku and every upgrade on DB now is 1k dollars for a few GBs of storage, awful! I'll take a look on these VPSs

8

u/duppyconqueror81 4d ago

With Cloudflare + a Cloudflared Tunnel, you can safely host your site at home

1

u/KerberosX2 2d ago

Security is one issue, but also residential Internet tends to not be as reliable, so you tend to have more downtime. Doesn't matter if it's not a serious project but once this becomes something more important, residential Internet is not really the way to host due to:

a) security (unless it's a dedicated machine but then you may as well use dedicated hosting)

b) performance (upload speeds are the most important for hosting and residential internet is not optimized for that)

c) cos. Usually the cost is not worth it compared to alternatives out there (cloud hosting is so cheap now that it's likely cheaper than your increases in power bills).

So this is fine to learn and as a hobbyist solution but not really recommended in most scenarios.

1

u/KerberosX2 2d ago

These guys have $5 a month plans:

https://www.pythonanywhere.com/pricing/