The invention provides an optical detector for multi-component gas in a closed or semi-closed space, the quality of the ambient air in the closed or semi-closed space is detected in real time by adopting a spectral analysis method, so that the optical detector has higher technical advancement and scientificity compared with the conventional measurement by adopting an electrochemical method. The problems of low measurement precision, short service life, long recovery time, poor poison and overload resistance, inconvenience in maintenance and the like of the conventional instrument are solved. Multiple technologies such as an infrared spectrum technology, an ultraviolet spectrum technology and an array sensing technology are fused, complemented with one another and complemented with one another, so that the detection resolution is improved, the detection types and capabilities of the detector are expanded, and the detection sensitivity of the detector is improved. Carbon monoxide, nitric oxide, carbon dioxide, oxygen, methane, sulfur dioxide, unsymmetrical dimethylhydrazine, hydrogen sulfide and volatile organic compound gas can be qualitatively, quantitatively and accurately detected on line at the same time.