I used closed-cell foam tape with adhesive on one side. Stuck it to the deck and it squishes down and seals the gap between deck and coaming so if you bury your rail, or if spray runs along the deck from the front it does not trickle into the cockpit.
Found it at a boat store. Must be closed cell, so it can't become waterlogged. If you don't live near a good store, you can probably order online, e.g. from
https://www.fisheriessupply.com/. Something like this
Marine WeatherSeal Tape.