In the age of HBO's "The Deuce," "Boogie Nights" looks like a time-honored masterpiece, but when the sprawling period epic about the golden age of porn filmmaking opened 20 years ago this week (on October 10, 1997), moviegoers didn't exactly embrace it.

The subject matter was still too skeevy to draw mainstream or even art-house audiences, yet not nearly explicit enough to draw the trench coat crowd. "Most people don't share my moral sense," writer/director Paul Thomas Andersonexplained in 1999, "which is, 'I'll masturbate, but I have to clean it up very quickly afterwards.'" No wonder "Boogie Nights" wasn't exactly a hit.

Nonetheless, it earned three Oscar nominations, made a serious leading man out of Mark Wahlberg, gave Burt Reynolds his best role of the last 35 years, put Anderson on the map, and gave early career boosts to Philip Seymour Hoffman, John C. Reilly, Don Cheadle, and Thomas Jane.

These days, "Boogie Nights" evokes double nostalgia, both for the disco 1970s, lovingly recreated in the movie's costumes and soundtrack, and for the 1990s, when Hollywood studios still nurtured indie directors and let them realize their visions instead of plucking them fresh from Sundance and assigning them to direct CGI blockbuster franchise sequels.

"Boogie Nights" had a famously fraught production history, including some life-imitates-porn moments and a near-fistfight between Reynolds and Anderson. Here are some of the things that, uh, went down.
1. Anderson (above, right) grew up in the Valley and was, as a teen, obsessed with the porn industry existing all around him. He was still in high school when he made his first movie, a 32-minute short called "The Dirk Diggler Story," a "Zelig"-like mockumentary about a fallen porn star. In addition to the protagonist, several other characters and much of the dialogue would find their way into "Boogie Nights" a decade later.

2. The Dirk Diggler of Anderson's "Boogie Nights" screenplay bears a strong resemblance to legendary porn actor John Holmes, and not just in terms of length. There's Holmes' rise to fame via the series of "Johnny Wadd" thrillers (echoed in Dirk's "Brock Landers" movies), his biographical documentary directed by a colleague ("Exhausted," the inspiration for the movie that Julianne Moore's Amber makes about Dirk), and his alleged involvement in the Wonderland drug murder case (the inspiration for the whole nightmarish sequence involving Alfred Molina's Rahad Jackson).
3. New Line wanted to be the next Miramax, and they needed their own Quentin Tarantino. After seeing Anderson's first film, "Hard Eight," they thought he might be it. They decided the director's phone-book-sized script about a guy with a 13-inch penis was edgy enough, as long as he agreed to keep it under three hours and keep the rating down to an R.

4. Anderson initially wanted Leonardo DiCaprio to star as Dirk Diggler, but the actor begged off, citing his commitment to star in "Titanic." But he recommended his "Basketball Diaries" co-star Wahlberg. "You know," Anderson joked, "Mark came to me and said, 'I've got an inch on Leo.' I said, 'Really?' And he showed it to me. And then I hired him." Years later, DiCaprio would cite turning down "Boogie Nights" as his "biggest regret."
5. The role of Jack Horner, the porn filmmaker who becomes a surrogate father to Dirk and an ad hoc family of cast and crew members, was hard to cast. Before hiring Burt Reynolds, Anderson considered actors as diverse as Albert Brooks, Harvey Keitel, Bill Murray, Jack Nicholson and Sydney Pollack.

6. Warren Beatty expressed interest, but he ultimately acknowledged he just wanted to be associated with the project because the 59-year-old star saw himself more as Dirk. ("I think he was joking and not joking," Anderson mused.)7. Samuel L. Jackson, who'd played the villain in "Hard Eight," turned down the role of Buck Swope, the porn actor who dreams of selling stereos. His response to the script, Anderson recalled, was "What the hell is this?" After Moore vouched for the young director, Cheadle took the part and turned it into a career-boosting showcase.

8. There were a number of real-life porn actors in the cast, mostly as extras, though Nina Hartley had the biggest part as the emasculating wife of Little Bill (William H. Macy). Anderson hired them to help make sure he was depicting the porn world accurately, but sometimes, things got a little too much like the real thing. Hartley would often walk around the set in the nude because that's what she was used to doing on porn sets, even though it unnerved Anderson's cast and crew. She also wondered aloud why she couldn't just have sex in her sex scenes, since she found simulating sex much more complicated. During one scene, some of the actors and crew claimed she and her partner really were having sex, but she insisted later that his penis wasn't venturing where everyone thought it was going; it just wasn't taped to his thigh like it should have been.
9. Like her character, Heather Graham (Rollergirl) seldom took off her skates, even when cameras weren't rolling.

10. Speaking of penises, the movie's most famous special effect was the prosthetic Diggler that Wahlberg shows off in the final scene. The first one that the make-up team built was John Holmes-sized, but it just looked too huge to seem real, so they built a shorter one, still large enough for Marky Mark to hide his actual funky bunch inside.
11. In fact, the make-up artists built several, in case of breakage. Wahlberg also whipped it out during the sequence where Dirk and Amber are shooting a sex scene; it doesn't appear on camera then, but Wahlberg wanted to get a rise out of Moore. Most of the time, however, the package shown straining against the confines of Dirk's bellbottoms is just a woman's stocking filled with birdseed. The propmakers left the stocking in a warm trunk, where its seeds started to sprout, so they had to make another one.

12. During one scene where Little Bill grumbles about having caught his wife being sodomized by another man, Macy repeatedly muffed his line and said it backwards: "My f**king wife has an ass in her c**k." Anderson decided he preferred the mistake and kept it in the film.
13. While Anderson allowed Macy and others to ad lib, he insisted that Reynolds stay on script. Reynolds became irked and felt that the relatively inexperienced director wasn't giving him the respect he deserved as a veteran movie star. The two men argued loudly, and Reynolds swung a fist that might have hit Anderson in the face had a crew member not held back his arm.

14. Why is Molina the only actor in his scene not distracted by the firecrackers going off at random intervals? Because he's wearing a hidden earpiece piping in "Sister Christian" on a continuous loop.
15. If the song "You Got the Touch," which Dirk records during his dubious effort to branch out into music, sounds familiar, it's because it originally appeared on the soundtrack of the first "Transformers" movie -- the 1986 cartoon, that is. Dirk's other song, "Feel the Heat," was composed by Anderson and Reilly.

16. Avant-garde satirical film director Robert Downey Sr. (yep, Iron Man's real-life dad) shows up in a cameo as the record label executive. With Downey's permission, Anderson cribbed the kid setting off firecrackers from Downey's 1969 movie "Putney Swope," as well as Buck Swope's last name.
17. Anderson had to submit the film to the MPAA 18 times, cutting a few frames each time from scenes the ratings board found too risqué, in order to avoid an NC-17 rating and earn the R rating he was contractually obliged to deliver. In the end, the difference between NC-17 and R turned out to be only 45 seconds worth of film. "I don't miss it at all," Anderson said of the snipped footage.

18. Still, Anderson's cut was over three hours long, making both test audiences and executives at New Line restless. Studio co-founder Bob Shaye made his own two-hour cut of the film and screened it for a test audience in Pasadena. Before the screening, the then-unknown director walked among the viewers in line and bad-mouthed his own film, saying, "This movie sucks. You're gonna hate it. This movie sucks," so that Shaye's cut would earn even lower test scores than his own. Eventually, both sides reached a compromise, resulting in a 155-minute release. Among the lost scenes: Dirk learns his parents have been killed in a gruesome car crash, which is then briefly shown on screen.
19. "Boogie Nights" reportedly cost $15.5 million to make. It earned back $26.4 million in North America and another $16.7 million overseas.

20. The Academy nominated "Boogie Nights" for three Oscars: Best Original Screenplay, Best Supporting Actress (Moore), and Best Supporting Actor (Reynolds). It was shut out of all three categories.
21. In 2015, Reynolds said that, to this day, he still hasn't ever watched "Boogie Nights" all the way through, and that he turned down an offer to appear in Anderson's follow-up, "Magnolia." "I'd done my picture with Paul Thomas Anderson, that was enough for me," he said. Wahlberg, who recalled Reynolds trying an Irish accent for his role in rehearsals, said in 2014 that he believed Reynolds' evident ill will toward what could have been his career comeback role had consequences. "He would have won the Oscar," Wahlberg said, "had he not dug such a hole for himself."