Electrospinning is affected by high variability, and an accurate setting of process parameters is fundamental for producing high quality nanofibers. This work aims at determining the optimal values of the main process parameters (polymer concentration, polymer feed rate, and voltage) as a function of the environmental factors (temperature and humidity), in order to obtain nanofibrous materials within a specific range of fiber diameter and porosity, and at the same time to minimize production defects. The response surfaces of diameter, porosity, and defects are first determined with a central composite design. These surfaces are then employed as an input for the optimization problem: diameter and porosity surfaces are used to constrain an admissible region, where the minimum of the defect surface is searched. The approach is tested on a prototype electrospinning machine. The estimated response surfaces capture the variability of the process with respect to both production parameters and environmental factors, and are capable of getting the optimal values of the process parameters. © 2017 Wiley Periodicals, Inc. J. Appl. Polym. Sci. 2017, 134, 44740.