LONDON — Gandalf may be willing to travel to the most dangerous corners of Middle Earth to fight evil, but Ian McKellen, the actor who plays him, won’t go to Russia.

McKellen, the star of the “Lord of the Rings” and “Hobbit” films, said he was advised “not to go to Russia” by the U.K. government’s foreign affair department because of the country’s anti-gay laws.

“That’s why I can’t go… they couldn’t protect me from those laws,” McKellen told the Radio Times magazine. “Two and a half hours from London! In the land of Tchaikovsky, Diaghilev, Rudolf Nureyev — gay artists whose sexuality informed their work.”

Russia passed a law in June that outlaws the provision of information about homosexuality to people under 18.

McKellen, who came out as being gay at the age of 49, has campaigned against homophobia in the past.

He said he had sympathy for gay, A-list thesps who keep their sexuality a secret.

“It’s true of A-lists all over the world — A-list priests, A-list politicians. What will other people think? Will people still vote for me? Will people come and see me act?

“They’re warned by the people who surround them — agents and managers, who have a living to make and are worried that the actor will get pigeonholed.

“I don’t think the audience gives a damn. You don’t have to be straight to play Gandalf. Anyway, who says that Gandalf isn’t gay? I loved it when J.K. Rowling said that Dumbledore was gay.”