Nginx之二:nginx.conf簡單配置(參數詳解)

vim /usr/local/nginx/conf/nginx.conf


#user  nobody;#程序運行使用賬戶
worker_processes  1;#啓動的進程,通常設置成和cpu的數量相等
#全局錯誤日誌級PID文件
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;
events {
    use epoll;    #epoll是多路複用IO中的一種方式
    worker_connections  1024;    #單個後臺進行的最大併發連接數
 #總併發數爲worker_processes*worker_connections的乘積
}
http {
    include       mime.types;    #定義mime類型,類型有mime.types文件定義
    default_type  application/octet-stream;
    #日誌格式
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  logs/access.log  main;
    #sendfile定義nginx是否調用sendfile函數,對於普通應用,必須開啓,如果用來磁盤IO負載應用,可設爲off,平衡磁盤與網絡IO處理速度
    sendfile        on;
    #tcp_nopush     on;
    #連接超時時間
    #keepalive_timeout  0;
    keepalive_timeout  65;
    #開啓gzip壓縮
    gzip  on;
    gzip_disable "MSIE [1-6]."
    #設定請求緩衝
    client_header_buffer_size    128k;
    large_client_header_buffers  4 128k;
    #設置虛擬主機配置
    server {
        listen       80;#監聽接口80
        server_name  www.nginx.com;   #設置主機名
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
            root   /var/www/nginx;   設置網頁根目錄位置
            index  index.html index.htm;  定義索引文件的名稱
        #
# 定義錯誤提示頁面
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
#靜態文件,nginx自己處理
        location ~ ^/(images|javascript|js|css|flash|media|static)/ {
            
            #過期30天,靜態文件不怎麼更新,過期可以設大一點,
            #如果頻繁更新,則可以設置得小一點。
            expires 30d;
        }
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
#PHP 腳本請求全部轉發到 FastCGI處理. 使用FastCGI默認配置.
        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi_params;
        }
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
#禁止訪問 .htxxx 文件
        location ~ /\.ht {
            deny  all;
        }
    }
}

#Nginx的location配置語法

location = URI  只對當前路徑生效(精確匹配指定的路徑,不匹配子路徑及文件);

location ^~URI 不使用正則表達式;

location ~URI (區分大小寫) 及 location ~* (不區分大小寫)  模式匹配URI,可以使用正則表達式;

location URI 對當前路徑及子路徑的所有對象;


在匹配中優先級自上而下;


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