首頁  >  文章  >  後端開發  >  Nginx location 設定心得

Nginx location 設定心得

WBOY
WBOY原創
2016-08-08 09:25:221087瀏覽

關於Nginx location 設定相關資料很多,由於在配置location時候老是出現404 Not Found,查閱了很多資料,總算是找到了答案。

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

          location /hsc {
            root   /home/hsc/nginx;
            index  index.html;
        }
        location / {
            root   /home/hsc/nginx/hsc;
            index  index.html index.htm;
        }
}
如上一個簡單server配置,在瀏覽器中輸入127.0.0.1 和127.0.0.1/hsc其請求的結果是一樣都是/home/hsc/nginx/hsc 目錄下的index.html

解釋下: 127.0.0.1 會配對到 location / 然後root(表示根目錄) 為/home/hsc/nginx/hsc 然後nginx 再去找/後面的內容這裡為空,所以就找根目錄下的內容。

27.0.0.1/hsc   會配對到 llocation /hsc 然後root(表示根目錄) 為/home/hsc/nginx 然後nginx 再去找/後面的內容這裡為hsc這個目錄,所以就會切換到/home/ hsc/nginx/hsc目錄下。

以上就介紹了Nginx location 設定心得,包含了方面的內容,希望對PHP教學有興趣的朋友有幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn