The potential upsides of fog computing are undeniable, including better near-real-time response, reduced transmission costs and analysis for IoT, which will further have a significant impact on operation of factories, enterprises, organizations and even the quality of our life. However, due to the resource-constrained nature, heterogeneity and distributed nodes, how to manage the extraordinarily complex fog computing resources is necessary to improve the QoE of users. This paper investigates the rational resource allocation for fog computing from the cross-layer point of perspective, and formulates the resource allocation scenario as Cloud–Fog–User market which is composed of cloud center devices, fog nodes, and user devices. Firstly, the resource market is divided into Cloud–Fog market containing cloud layer and fog layer, and Fog–User market containing fog layer and user layer based on different scenarios separately. The paper proposes a market-based framework for fog computing networks, which enables the cloud layer and the fog layer to allocate their resources in the form of pricing, payment and supply–demand relationship, while analyzes the relationship among resource allocation participants in the market. Then the paper investigates the utility optimization models from the viewpoints of both the participants of respective markets, so as to optimize optimal payment and optimal resource allocation via convex optimization techniques, and proposes a gradient-based iterative algorithm to optimize the utilities, respectively. Finally, experimental results have displayed the performance of convex analysis results and effectiveness of the proposed algorithm.