The chameleon gravity model postulates the existence of a scalar field that couples with matter to mediate a fifth force. If it exists, this fifth force would influence the hot X-ray emitting gas filling the potential wells of galaxy clusters. However, it would not influence the clusters weak lensing signal. Therefore, by comparing X-ray and weak lensing profiles, one can place upper limits on the strength of a fifth force. This technique has been attempted before using a single, nearby cluster (Coma, z = 0.02, Terukina et al. 2014). Here we apply the technique to the stacked profiles of 58 clusters at higher redshifts (0.1 < z < 1.2 ), including 12 new to the literature, using X-ray data from the XMM Cluster Survey (XCS) and weak lensing data from the Canada France Hawaii Telescope Lensing Survey (CFHTLenS). Using a multiparameter MCMC analysis, we constrain the two chameleon gravity parameters (β and φ ∞ ). Our fits are consistent with general relativity, not requiring a fifth force. In the special case of f (R) gravity (where β = 1/6), we set an upper limit on the background field amplitude today of |f R0 |< 6 × 10 −5 (95% CL). This is one of the strongest constraints to date on |f R0 | on cosmological scales. We hope to improve this constraint in future by extending the study to hundreds of clusters using data from the Dark Energy Survey.