To get to Nerja by train, you will need to go to Malaga first, to the RENFE station there. You can also go to the RENFE train station in Granada, though Malaga is much closer, only 50 km. Granada is about 100 km away.
After taking the train, you will need to take the bus or rent a car.