在部署好Nginx服務器后,輸入IP地址和端口號,返回403 Forbiddent
查看日志error.log,發現報錯信息為:
directory index of "xxx" is forbidden
其中,xxx是在/etc/nginx/nginx.conf中指定的root目錄。
報錯根因:直接使用IP地址和端口號訪問時,需要指定index,如果未指定,出現該報錯。
這時候,可以在nginx/nginx.conf中添加配置:
autoindex on; # 自動索引
這樣再次訪問的時候,就會列出所有的資源索引。
【注意】修改nginx.conf后,記得重啟服務才能生效。