The generator (IDG) is located on the accessory gearbox
The general design is to group elements that need to be driven by the engine around one "accessory gearbox" which is located away from the engine centerline. A driving axial shaft in therefore required. In some cases, there are multiple accessory gearboxes.
The IDG goes on the accessory gearbox. On the image below, #1 is the IDG pad where the IDG is mounted (IDG removed):
Accessory gearbox on CFM56-5, source Training Manual
The accessory gearbox is located at the bottom of the engine, driven by N2
Usually the accessories are located at the bottom of the engine fan case, making them and the gearbox away from airflow and more accessible for maintenance.
Indeed putting obstacles to the airflow is not good for the engine efficiency, so the radial driving shaft location is chosen to minimize aerodynamic effects, usually within, or behind, one of the struts of the fan frame.
Here a view of an accessory gearbox with its accessories in place:
The gearbox itself (without accessories) with its radial shaft:
CFM56 Gearbox (without accessories) and radial drive shaft, source
How the N2 shaft drives the accessories using a radial (vertical) shaft:
When this is not possible to put the accessories here, because the clearance between the engine nacelle and the ground is too limited, they are moved sideway as in the B737 with a CFM56-7.
CFM56-7B Accessory gearbox, source
This gives the nacelle of the B737 its characteristics squared profile:
The arrow points at the accessory gearbox (source: B737 AMM)
Accessories are driven by a radial shaft, or a set of shafts with angles and gearboxes as required. Energy is taken from the HP spool (N2), or the IP (intermediate pressure in engines with 3 spools, like in many Rolls Royce engines. Also N2).
Source: The Jet Engine, Rolls Royce
The generator can be seen on the right of the accessory box.
The starter is another accessory. When starting the engine, the radial driving shaft is used in the other direction, the accessory box drives the engine shaft. Sometimes the starter and the generator are a single component, an electric motor being reversible. See How is a turbine engine rotated for starting and inspections?