If I have built one and don't want mobs to come out, do I have to close the portal?
In my experience, that's why I always have lava or stone fences around it!
As far as I can remember, mobs came through that but in the old versions I don't remember which one
Yes, mobs can go through and the portal even spawns them.
Yes, you can. Nether mobs can't go through the portal if you are not in the Nether. Sometimes zombie piglins spawn on portals, but they can't really go through if you're not in the nether.
Then what is possible?
What do you think?
If you can't go when I'm in the upper world, what can you do?
If you are in the upper world, the Nether and all mobs in the Nether do not load. So the mobs in the Nether can't do anything when you're in the overworld.
So if a zombie piglin walks around your portal in the upper world, then it spawns on the portal, which sometimes happens
Do they only spawn when I light the portal or already when I place the blocks?
Only if your portal is active, i.e. If you have lit it.