We investigated the effect of photoperiod on ileal morphology, barrier function, short-chain fatty acid (SCFA) contents, microbial flora, melatonin expression, and synthesis in laying ducks. After adaption, a total of 180 Jinding laying ducks (252 days old) were randomly divided into three treatments, receiving 12L (hours of light):12D (hours of darkness), 16L:8D, or 20L:4D. Each treatment had six replicates with 10 birds each. The formal experiment lasted 58 days. Compared with 12L:12D, the significantly higher values of villus height and goblet cell percentage (GCP) were observed in 16L:8D treatment, accompanied with the higher mRNA relative expression of zonula occludens-1, zonula occludens-2, zonula occludens-3, claudin-1, occludin, and mucin 2 (P < 0.05). Besides, significantly higher values of acetate and propionate, butyrate and total SCFA concentrations were simultaneously observed in ileal chyme of 16L:8D treatment (P < 0.05). For the ileal microbial community, the results of principal coordinate analysis (PCoA) visually presented that three photoperiod groups were mainly scattered into three clusters, indicating that the microbiota composition in different photoperiod treatments were quite dissimilar. Lower values of Shannon indicators were observed in the 20L:4D treatment (P < 0.05), meaning that the microbiota α-diversity decreased in the 20-h photoperiod. The relative abundance of Actinobacteria, Fusobacteria, and Proteobacteria at phylum level and Fusobacterium, Clostridium_sensu_stricto_1, and Pectobacterium at genus level kept an appropriate balance in the 16L:8D photoperiod. Melatonin level in serum decreased with the increasing photoperiods at 6:00 and 12:00, which was consistent with melatonin receptor expressions in the hypothalamus and ileal tissue. Meanwhile, the adenosine 3′,5′-cyclic phosphate (cAMP) contents were significantly downregulated in the pineal gland (P < 0.05), in response to the increase in photoperiod. In conclusion, an appropriate photoperiod could improve ileal morphology, barrier function, SCFA profile, and microbial flora, which may be attributed to the appropriate regulation of the circadian rhythm through melatonin as well as its receptor expression, and 16 h could be an adequate photoperiod for laying ducks.