Due to the high permeability of distributed energy connected to distribution network, there will be more harmonic current and resonance phenomena in the microgrid system when the nonlinear loads are connected, resulting in voltage distortion at the point of common coupling (PCC). Aiming at the problem of voltage distortion, this paper proposes an optimal virtual impedance harmonic suppression method based on the grid-connected inverter. By reshaping the output impedance of grid-connected inverter, the PCC voltage harmonics are effectively suppressed. Considering harmonic components and load types, the PCC voltage harmonic suppression coefficient is used as the evaluation standard to obtain the optimal combination mode of the resistance-inductance virtual impedance (RIVI). Moreover, to achieve the current tracking without error, the proportional integral multi-quasi-resonant (PIMQR) controller is added to the RIVI control system. Finally, based on the RT-BOX hardware-in-the-loop experimental platform, different working conditions are experimentally verified. The experimental results prove the effectiveness and accuracy of the proposed RIVI control method.