Nginx主配置文件詳解

    Nginx安裝後主配置文件在/usr/local/nginx/conf目錄下,接下來看下介紹下主配置文件吧。

     主配置文件分爲兩部分主配置段和協議配置段:

    主配置段

    #使用的用戶名和組

        user  nginx    nginx ;

      #指定worker進程數

     worker_processes   1;

      #指定錯誤日誌文件路徑,日誌級別可選項 [ debug| info | notice | warn | error | crit]

       error_log /usr/local/nginx/logs/error.log crit;   #crit級別最低記錄的信息很少;

   #指定pid文件所在路徑

       pid   /usr/local/nginx/var/nginx.pid;


    events{

    #使用的網絡I/O模型,linux建議epoll

    use epoll;

    #允許的連接數

    Worker_connections  1024;

    }


    協議配置段

    

http{

    #設置mime類型

    Includemime.types;(/usr/local/nginx/conf/mime.types)

    # 當用戶訪問的頁面帶有bin,exe,dll,deb,dmg,iso,img,msi,msp,msm等後綴的文件時直接下載

    default_type application/octet-stream;

    #設置默認字符集

          charsetgb2312;

          ......

    #設置虛擬主機

    server{

    #設置監聽端口

    listen80;

    #設置主機名

    server_namelocalhost;

    #設置虛擬主機所在的目錄(如果爲/那麼此虛擬主機的目錄就爲安裝目錄下)

    location / {

    #設置根目錄

    root html;

    #設置首頁文件

    Indexindex.htmlindex.htm;

    }

    #設置狀態也爲5XX系列的錯誤頁面(安裝目錄下的/html/50x.html

    error_page500502503504/50x.html

    #設置當用戶訪問50x.html頁面時nginx尋找50x.html的路徑

    location =/50x.html{

    roothtml;

    }

    }

    }

    由以上內容可以看出nginx的主配置文件的組成:

......

event{

....

}

http{

....

server{

....

location{

...

}

}

server{

....

location{

....

}

}

}




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章