解决访问nginx首页404的过程
作者:java叶新东老师
这篇文章主要介绍了解决访问nginx首页404的过程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
访问nginx首页404的方法
正常情况下,启动nginx后访问地址 http://localhost
应该是能进入到nginx 的欢迎首页的;但是当访问后却显示了404页面,
我们当前的 html 文件路径为:/root/c_nginx_module/html/index.html
这种情况一般都是 nginx root目录(根目录)未配置好导致的,那我们只要保证根目录下有html,或者指定一个有html的根目录就行啦!
解决方案 1:在根目录加上html文件
以下通过 -t
命令查看到,nginx 的根目录是 /usr/local/nginx/
^Croot@PAw9033927:~/c_nginx_module# ./nginx -t nginx: [emerg] open() "/usr/local/nginx/conf/nginx.conf" failed (2: No such file or directory) nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
然后,我们进入到 nginx的根目录,创建一个html目录,在html目录下创建一个 index.html 文件
cd /usr/local/nginx/ mkdir html cd /usr/local/nginx/html touch index.html # 在文件内加入 html 代码 vi index.html
然后再次启动就可以访问了
解决方案 2:指定根目录
刚刚说了,我们当前的 html 文件路径为:/root/c_nginx_module/html/index.html
,那我们就把根目录指定为 /root/c_nginx_module
就行了
在 nginx.conf 配置文件中,在 location
块下将root的值改为 /root/c_nginx_module/html
location / { root /root/c_nginx_module/html; # 改这里 index index.html index.htm; }
然后重启就可以了
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。