I would. although there are limitations depending on your legal status. Mexican nationals will of course have dibs on beach front property. having a house one block away form the beach is a good compromise IMO. I would first make sure you are using a vetted agent or one that a friend or family member has recommended. using an agent rather than doing the house hunting has its perks too as you will not be looked at as el gringo wanting to buy a house, were you might find someone less willing to haggle with price if they know the buyer is from outside of Mexico.
According the Mexico's law in article 27 of the Mexican Constitution, a foreigner can’t directly acquire a property within 50 km from the water and 100 km from the border. This area is known as the restricted zone. However, Mexico’s Foreign Investment Law allows foreigners to acquire indirectly a property in the restricted zone through two legal entities:
Bank trust (fideicomiso): This is when a bank is hired on the client’s behalf to hold the title deed.
Mexican Corporation: It requires two shareholders and one of them must have a Mexican Tax ID; for which he needs to get and maintain a permanent resident visa. With the Mexican Corporation you can own multiple properties. Nevertheless, it requires the corporation to do a monthly and an annual report of taxes. It is a good idea to hire an accountant if you choose this entity.
Today, foreigners have many opportunities to purchase or invest in Mexican real estate.
In much of the in-land portion of Mexico, the purchase of real property by foreigners has the same legal basis as in the United States. But if you want beach side homes, The Mexican constitution of 1917, prohibited foreign ownership of residential real property within approximately 31 miles (approximately 50 km) of any coastline and 62 miles (approximately 100 km) of its natural borders. All of Baja California is included in this “restricted zone.”
This was done to protect Mexican citizens from losing the ability's to buy homes near the beach because rich foreigners buy would end up buying them.