路由 - nginx訪問不了根目錄下的文件怎么解決?
問題描述
我的是阿里云的一臺Ubuntu16.04主機(jī),nginx安裝成功了,訪問IP(如:0.0.0.0)顯示的是nginx歡迎頁面,但我訪問0.0.0.0/index.html顯示404,在主機(jī)輸入curl 127.0.0.1/index.html打開的是404頁面文件。也就是說所有的根目錄的文件都沒有路由,請問怎么解決這個問題呢?
問題解答
回答1:Ubuntu apt 安裝 nginx 默認(rèn)配置/etc/nginx/conf.d/nginx.conf 默認(rèn)配置
/etc/nginx/sites-available/default 默認(rèn)localhost配置
/var/www/html/ 默認(rèn)工作目錄
http://localhost/index.nginx-debian.html 默認(rèn)歡迎頁全url
所以你需要編輯 /etc/nginx/sites-available/default root那行,目錄改成自己的目錄。
回答2:nginx安裝目錄下的conf/nginx.conf配置如下:
server {listen 80;server_name localhost;location / { root html; index index.html index.htm;}}
其中root屬性指定了訪問的文件所在根目錄,index屬性指定默認(rèn)的訪問頁面,location /表示匹配所有請求。
頁面報404,那么你就到root指定的目錄下查看是否有index.html文件
相關(guān)文章:
1. macos - mac下docker如何設(shè)置代理2. 請教各位大佬,瀏覽器點(diǎn) 提交實(shí)例為什么沒有反應(yīng)3. dockerfile - 我用docker build的時候出現(xiàn)下邊問題 麻煩幫我看一下4. angular.js - angularjs的自定義過濾器如何給文字加顏色?5. dockerfile - 為什么docker容器啟動不了?6. javascript - web網(wǎng)頁版app返回上一頁按鈕在ios設(shè)備失效怎么辦?安卓上可以,代碼如下,請大神幫助,萬分感謝。7. 新手 - Python 爬蟲 問題 求助8. mysql - AttributeError: ’module’ object has no attribute ’MatchType’9. javascript - JS設(shè)置Video視頻對象的currentTime時出現(xiàn)了問題,IE,Edge,火狐,都可以設(shè)置,反而chrom卻...10. apache - 本地搭建wordpress權(quán)限問題
