Evolution of the N = 20 and N = 28 shell closures in neutron-rich nuclei