Close the door until it hits against the nail head, leaving a mark on the edge of the door. Drill a hole large enough for the protruding nail to fit into when the door is closed. Many new doors are not very secure. They may be hollow core doors or doors with lots of glass in them. Those need to be either replaced or strengthened.
Replacement is simple, but expensive.
Solid core wooden or steel doors are recommended. If the cost of replacement is too expensive for you, look into the possibility of strengthening the door with plywood, sheet metal or plastic. Even better is a sheet of galvanized metal. Salvage yards are good sources for such materials. Glass in doors can be covered by one of the modern plastic materials available.