Dielectric confinement of excitons in type-I and type-II semiconductor nanorods