Steven Gerrard’s men reached the stage after winning through four qualifying ties, against Shkupi of Macedonia, NK Osikej of Croatia, Slovenians Maribor and FC Ufa of Russia.
It is the first time the club have reached the group stages of either European competition since the 2010/2011 Champions League.
Villarral finished fifth in La Liga last season and qualified automatically for the group stages, while Rapid Wien came through two qualifying ties after a third place finish in the Austrian Bundesliga.
The group is completed with Spartak who finished third in the Russian Premier League. That was enough for entry to the Champions League qualifiers but they dropped into the Europa League after defeat to Greek side PAOK.
Rangers have faced two of their future opponents previously in European competition. The first was against Rapid Wien in the 1964-1965 European Cup. The Ibrox side one both legs with a 3-0 aggregate success to progress to the quarter-finals.
Villarreal were opponents in the last-16 of the Champions League in 2006. Rangers drew both legs with the Spaniards emerging victorious on away goals. The fixture at Ibrox finished 2-2, whereas it was 1-1 in El Madrigal. The Yellow Submarines would reach the semi-final where they were defeated by Arsenal.
Rangers will face Spartak Moscow for the first time having played against both Dynamo and CSKA Moscow previously.
The first group fixture will take place on 20 September.