How to fix a deck railing that is falling off?
It appears that the rim joist is pulling away from the joists to which it's nailed due to the outward forces on the railing.

You could screw the rim joist to the joists (where those nails are now), which might give a bit more holding power, but you wouldn't gain a lot.  Using lag bolts in this situation should be avoided because they won't hold well in the end-grain of the joists.

I'd suggest adding angle brackets like these, on both sides of each joist.  Offset them slightly vertically so the screws from either side of the joist don't interfere with each other.  Use an appropriate screw length (2.5 inches would work for double joists).



The 4x4 posts for the railing are connected to the rim joist with bolt(s).  If these 4x4s connect next to one of the joists (ideally it would, and the one shown in your pictures seems to be), then you could add a deck post bracket if there isn't one already which transfers the railing force from the bolt to the joist.  This would replace the aforementioned angle bracket on one side of the joist.