Nginx配置文件詳解

[root@server1 sbin]# vim /usr/local/nginx/conf/nginx.conf
user  nobody;    //定義nginx運行的用戶和組
worker_processes  1;    //nginx進程數,建議設置爲等於cpu總核心數
error_log  logs/error.log;    //全局錯誤日誌定義的類型 [ debug | info | notice | warn | error ]
pid        logs/nginx.pid;    //進程pid文件
events {
    worker_connections  1024;     //單個進程最大的鏈接數
}
//設置http服務器,做爲反向代理功能提供負載均衡
http {
    include       mime.types;          
    default_type  application/octet-stream;     //默認文件類型
    sendfile        on;   //開啓高效文件傳輸模式,sendfile指令nginx是否調用sendfile用來輸出文件,對普通文件能夠設爲on,但若是用來下載應用磁盤I/O重負載應用,可設置爲off,以平衡磁盤與網絡I/O處理速度
    #tcp_nopush     on;  //防止網絡阻塞
    keepalive_timeout  65;    //鏈接超時時間超過65秒則斷開鏈接
    #gzip  on;     //開啓gzip壓縮

    //設置負載均衡的服務器列表
    upstream westos {
    server 172.25.16.1 weight=3;
    server 172.25.16.2 weight=1;
    }   

    //虛擬主機的配置
    server {
        listen       80;
        server_name  localhost;               //域名能夠有多個,用空格隔開
        //默認請求
        location / {
            root   html;      //定義服務器默認訪問站點目錄
            index  index.html index.html;   //索引文件的名稱
        }
       //定義錯誤提示頁面
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        //對php後綴結尾的文件請求採用負載均衡請求
        location ~ \.php$ {
            proxy_pass   westos;     //將請求轉向westos定義的服務器列表
       }
       //php腳本請求所有處理轉發到FastCGI處理
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi_params;
        }
        //禁止訪問.htxx文件
        location ~ /\.ht {
            deny  all;
        }
    }
  
php

相關文章
相關標籤/搜索