The massive data demand requires content distribution networks (CDNs) to use evolving techniques for efficient content distribution with guaranteed quality of service (QoS). The distributed fog-based CDN model, with optimal fog node placements, is a suggested aproach by researchers to meet this demand. While many studies have focused on improving QoS by optimizing fog node placement, they have rarely considered the impact on content distribution, affected by placement, usage changes, and delivery rates. Therefore, the practical approach to fog node placement for CDN services must examine its impact on content distribution. Further, current research on fog-based CDN lacks formal methods to address key challenges: R1) strategic placement of fog nodes to process end-user requests; R2) construction of a content distribution path with guaranteed QoS; R3) cost minimization of building a fog-based CDN model. We construct this as a joint optimization problem by considering four parameters: geographical regions, open public Wi-Fi access points (OPWAPs) locations, QoS, and cost to achieve research objectives R1–R3. As a solution, we propose a dual-step framework. First, a heuristic for optimal fog node placement based on geographic regions and OPWAP locations is proposed. Second, we propose two algorithms, Greedy Performance-based Node Selection (GPDS) and Greedy Fog Node Selection algorithm (GFNSA), for selecting fog nodes, minimizing the cost of building a fog-based CDN while achieving optimal content distribution paths. The results demonstrate that the proposed methods outperform the baseline techniques and provide near-optimal solutions to the problem.