In this paper, we investigate a generalized nonautonomous nonlinear equation which describes the ultrashort optical pulse propagating in a nonlinear inhomogeneous fiber. By virtue of the generalized Darboux transformation, the first- and second-order rogue-wave solutions for the generalized nonautonomous nonlinear equation are obtained, under some variable–coefficient constraints. Properties of the first- and second-order rogue waves are graphically presented and analyzed: When the coefficients are all chosen as the constants, we can observe the some functions, the shapes of wave crests and troughs for the first- and second-order rogue waves change. Oscillating behaviors of the first- and second-order rogue waves are observed when the coefficients are the trigonometric functions.