This is a great video showing how to install a ceiling fan using this special junction box.
Here are examples of how you can install a ceiling fan in an uncovered location such as a Pergola, Gazebo or Lanai. To install the fan properly, the canopy needs to be covered. The rest of the fan can be exposed directly to rain. In most cases, a box has been built with a junction box inside. This allows the fan canopy to mount flush to the bottom of the box. You can also mount the j-box to the bottom of a wide board and attach the canopy to the junction box, but there will be a gap between the j-box and fan canopy, but you cannot use this method for flush mount fans because the bracket needs to mount to a flat surface.
Example #8: This is an example of how NOT to install an outdoor fan, particularly a flush mount fan. This can allow rain to get inside the motor and ruin the fan or short it out and cause a fire. See Wet Rated Flush Mount Outdoor Ceiling Fans
Example #9: The image on the left shows how the wiring inside the canopy would be directly exposed to rain if left installed this way. The solution was to build a box between the joists and relocate the position of the fan. The fan picture is the Minka Aire Gauguin Model F581-BG.