Industrial Internet of Things (IIoT), or Industry 4.0, is an application of IoT in the industrial sector. Its main objective is to enhance product quality and optimize production costs by leveraging advanced technologies such as edge/fog/cloud computing, 5G/6G, and artificial intelligence. In the context of Industry 4.0, numerous devices and systems are interconnected to provide seamless services to users. However, with this interconnection comes the need to protect these devices and the information they transmit from cyberthreats and intrusions. In order to tackle this challenge, our proposed solution involves the utilization of deep learning (DL) models to develop an anomaly-based detection system. Our approach involves two powerful DL models, namely Convolutional Neural Networks (CNN) and Gated Recurrent Units (GRU). The proposed model's performance is studied within binary and multiclass classification using a new real-world industrial traffic dataset called Edge-IIoTset. The outcomes of our experiments showcased the efficacy of the CNN-GRU model that we proposed, surpassing the performance of recent related works in terms of performance metrics, including accuracy, precision, false positive rate, and detection cost. The combination of the two models CNN and GRU outperforms the GRU model with 88% of detection cost in multiclass classification for one traffic flow.