Based primarily on the real life of a Lithuanian girl Danguole Rasalaite, who ended up in Sweden after her mother took off and went to America. The film follows the events of Danguole's life pretty closely, with the main exception of the boy Volodja who is entirely fictional.
The town in which Lilja lives is in real life called Paldiski and is located in Estonia, not far from the capital Tallinn. The submarine base has now been destroyed. Some scenes are indeed shot in Paldiski, but many in Tallinn, in the districts of Kopli and Lasnamäe.
The trivia item below may give away important plot points.
The Swedish city at which Lilya arrives is Malmö. The footage was shot in the southern and eastern parts of the city center. For example, the tall gray buildings in the beginning and final scenes, seen in the background from the fatal bridge, are located in the district of Eriksfält. The apartment where Lilya is kept is located at Eriksfältsgatan. Poor Dangoule, the girl whose life this film was based on, was actually kept in an apartment in Arlöv, a town to the north of Malmö. The actual bridge she jumped off is crossing Trelleborgsvägen.