Want to eat healthy? Eat so much bad food that you get tired and bored with it. Want to be productive and not goto facebook? Find something you want to do so badly that you forget facebook. Want to be productive and not goto HN? Go there and read every article on the first page for 2 weeks, then become bored. Want to fall asleep upon entering your bed? Stay awake until you're tired -- if this means you'll be too tired for work, then you need to change your schedule, or find a way to work tired.
---
Visualize Jack Sparrow's compass -- it always points toward what you want. But compasses are balanced metal bars, with the magnetic end pointing toward, and the other end pointing away from what you want. Visualize the rod bending in half, so both ends point toward what you want. Now do this with your wants.
An underrated point, IMHO. When I find myself constantly surfing or otherwise distracting myself, there is invariably a good reason for it: I'm not that into what I'm doing at work. I wouldn't be any good at it if I did force myself to do it.
Excessive self-distraction is not a problem: it is a symptom of another problem.
Have no cookies at home? End up eating all the cookies at friend's house, event, etc, where I can't make there be no cookies.
Unproductive websites? End up replacing the "mental reboot" process with some other task.
Far away phone? Tolerance to the ring goes up so that I just don't care.
That all said, engineering the situation can be really effective, it just has to fit in your "natural rhythm" - When I start browsing, I always start with the 8 sites on my Chrome new tab page, so if I change those, I change how I browse.