1配置文件 /etc/nginxnginx.conf
- 會默認引入conf.d 下的所有以 *.conf結尾的文件
- 指定log 目錄 /var/log/nginx/access.log
2 default.conf 配置
- 指定了默認訪問的index.html 路徑 為 /usr/share/nginx/html
3 還有一種情況下 conf.d 下面為空的 則引入的為
則引入的 默認的index.html 在/var/www/html 下
重啟服務
sudo service nginx restart
疑難雜症之 啟動 映射主機無法訪問
docker run -p 8080:80 --name nginx_web2 -v /var/log/nginx/:/var/log/nginx -v /home/kk/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /usr/share/nginx/html/:/usr/share/nginx/html nginx
這樣啟動 一直 在主機無法訪問 經過測試 發現在 nginx.conf 里如果 直接把server 寫在 http內部 而不是通過include引入 則沒問題, 改成include引入方式則無法正常顯示,原因暫時未知
下面無法訪問
下面可以訪問
找到問題所在啦!!!!
重點在於 我們只是對 nginx.conf 做了 內外映射, 那么當執行nginx.conf時候其實是把這個文件讀取到container內部執行 所以nginx里寫的 include /etc/nginx/mime.types;
實際上是 內部的路徑,而不是外部的路徑!!!!
nginx 配置 header 頭部之 content-type
是通過 include /etc/nginx/mime.types; 引入,會根據不同的請求 資源類型 返回不同的 contenttype, 這很關鍵,比如 我們寫死 返回頭為 text/plain 則 在返回其他如json 或者 樣式 文件 就會客戶端不識別