The Internet of Things (IoT) is an innovative scheme providing massive applications that have become part of our daily lives. The number of IoT and connected devices are growing rapidly. However, transferring the corresponding huge, generated data from these IoT devices to the cloud produces challenges in terms of latency, bandwidth and network resources, data transmission costs, long transmission times leading to higher power consumption of IoT devices, service availability, as well as security and privacy issues. Edge computing (EC) is a promising strategy to overcome these challenges by bringing data processing and storage close to end users and IoT devices. In this paper, we first provide a comprehensive definition of edge computing and similar computing paradigms, including their similarities and differences. Then, we extensively discuss the major security and privacy attacks and threats in the context of EC-based IoT and provide possible countermeasures and solutions. Next, we propose a secure EC-based architecture for IoT applications. Furthermore, an application scenario of edge computing in IoT is introduced, and the advantages/disadvantages of the scenario based on edge computing and cloud computing are discussed. Finally, we discuss the most prominent security and privacy issues that can occur in EC-based IoT scenarios.