In this article, we study the problem of optimal index insurance design under an expected utility maximization framework. For general utility functions, we formally prove the existence and uniqueness of optimal contract and develop an effective numerical procedure to derive the optimal solution. For exponential utility and quadratic utility functions, we obtain analytical expression of the optimal indemnity function. Our results show that the indemnity can be a highly nonlinear and even non-monotonic function of the index variable in order to align with the actual loss variable so as to achieve the best reduction in basis risk. Due to the generality of model setup, our proposed method is readily applicable to a variety of insurance applications including index-linked mortality securities, weather index agriculture insurance, and index-based catastrophe insurance. Our method is illustrated by numerical examples where weather index insurance is designed for protection against the adverse rice yield using temperature and precipitation as the underlying indices. Numerical results show that our optimal index insurance significantly outperforms linear-type index insurance contracts in terms of basis risk reduction.