Different issue (
https://news.ycombinator.com/item?id=20172172), but my heuristics might work for you as well. I'm not a therapist, so take it with a pinch of salt.
1) Edit the host file to block nsfw websites on your computer: https://github.com/4skinSkywalker/anti-porn-hosts-file. Note that the host file blocks whole websites (e.g. reddit.com), not specific pages (reddit.com/r/news/).
2) Download a web/app blocker to lock down your browser during night time. I use https://heyfocus.com/?utm_source=focus_about, but there are several free apps to choose from.
3) Soul-search what really caused the compulsive behaviour. This lengthy process is less about finding "the ONE answer" and more about self-awareness. A good psychologist (a professional therapist who does not rely on prescriptions) can help you connect the dots. I was skeptical at first, but I've ended up enjoying the sessions.
4) Find a hobby that involves exploring open spaces: hiking, nature photography, bird watching, biking through the countryside... you need to feel that child-like freedom again. Modern life is like moving from one prison cell to the next, each one with a specific function. Your daily routine is likely defined by a string of tiny spaces: bedroom, bathroom, kitchen, sidewalk, car, office, repeat. Porn might be one way to escape from the ubiquitous wall, but I suggest you to explore other possibilities.
I wish you good luck! I hope you'll post your progress to this community in the future.