Unmanned aerial vehicles (UAVs) have been recently applied to improve physical-layer security in wireless communication networks. This work considers a cognitive relay network where UAV is used as a mobile relay to bridge the communication from a secondary transmitter to a secondary receiver. Our purpose is to maximize the secrecy rate under certain UAV trajectory and power constraints by designing a joint optimization algorithm. Solving the optimization problem is computationally challenging as the utility functions are non-concave and constraints are non-convex. Thus, an efficient iterative convex approximation algorithm based on a successive optimization approach is introduced to address the proposed non-convex optimization problems. The computer simulations show that our algorithm can achieve a rapid coverage rate and the UAV trajectory is optimized successfully. Results in this study demonstrate that the proposed design outperforms conventional schemes.