The detection and surveillance of ship targets in coastal waters is not only a crucial technology for the advancement of ship intelligence, but also holds great significance for the safety and economic development of coastal areas. However, due to poor visibility in foggy conditions, the effectiveness of ship detection in coastal waters during foggy weather is limited. In this paper, we propose an improved version of YOLOv8s, termed YOLOv8s-Fog, which provides a multi-target detection network specifically designed for nearshore scenes in foggy weather. This improvement involves adding coordinate attention to the neck of YOLOv8 and replacing the convolution in C2f with deformable convolution. Additionally, to expand the dataset, we construct and synthesize a collection of ship target images captured in coastal waters on days with varying degrees of fog, using the atmospheric scattering model and monocular depth estimation. We compare the improved model with the standard YOLOv8s model, as well as several other object detection models. The results demonstrate superior performance achieved by the improved model, achieving an average accuracy of 74.4% (mAP@0.5), which is 1.2% higher than that achieved by the standard YOLOv8s model.