ubuntu 13.04 nginx.conf 配置详解

1、nginx.conf 文件,路径为:/etc/nginx/agin.conf

#使用的用户和组
user www-data; 

#指定工作衍生进程数(一般等于CPU总核数或总核数的两倍)
worker_processes 4;

#指定PID存放的路径
pid /run/nginx.pid;

#指定文件描述符数量
worker_rlimit_nofile 51200;

events {
    #使用的网络I/O模型,linux戏台推荐采用epoll模型,freebsd系统采用kqueue模型
    use epoll;

    #允许最大连接数
    worker_connections 51200;
    # multi_accept on;
}

http {

    ##
    # 基础设置
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    server_names_hash_bucket_size 128;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # 日志设置
    ##

    #指定错误日志存放路径数, 错误日志记录的级别可选项为:[debug|info|notice|warn|error|crit]
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # 压缩设置
    ##

    gzip on;
    gzip_disable "msie6";

    gzip_vary on;
    # gzip_proxied any;
    gzip_comp_level 2;
    gzip_buffers 4 16k;
    gzip_http_version 1.1;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # nginx-naxsi config
    ##
    # Uncomment it if you installed nginx-naxsi
    ##

    #include /etc/nginx/naxsi_core.rules;

    ##
    # nginx-passenger config
    ##
    # Uncomment it if you installed nginx-passenger
    ##

    #passenger_root /usr;
    #passenger_ruby /usr/bin/ruby;

    ##
    # 虚拟主机设置
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

#mail {
#    # See sample authentication script at:
#    # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#    # auth_http localhost/auth.php;
#    # pop3_capabilities "TOP" "USER";
#    # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#    server {
#        listen     localhost:110;
#        protocol   pop3;
#        proxy      on;
#    }
# 
#    server {
#        listen     localhost:143;
#        protocol   imap;
#        proxy      on;
#    }
#}

2、default 服务主机配置文件,路径为:/etc/nginx/sites-available/default

#主机
server {
    listen 80;
    server_name www.demo.com;
    root /home/zxl/wwwroot/demo/;
    index index.php index.html index.htm;

    #如果没有可访问目录或文件
    if (!-e $request_filename) {
        #将访问路径跳转至根目录下的index.php接受处理
        rewrite  ^/(.*)$  /index.php/$1  last;
        break;
    }

    #处理请求路径满足匹配 .php  的响应
    location ~ \.php
    {
        #响应请求处理入口,使用php-fpm进行管理
        fastcgi_pass unix:/var/run/php5-fpm.sock;

        fastcgi_index index.php;
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    #配置静态图片文件客户端缓存时间
    location ~ .*\.(gif|jgp|jpeg|png|bmp|swf)$
    {
        expires 30d; #30天
    }

    #配置js、css文件客户端缓存时间
    location ~ .*\.(js|css)?$
    {
        expires 1h; #1小时
    }

    #设置访问日志保存格式
    #log_format access '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer"' '"$http_user_agent" $http_x_forwarded_for';

    #设置访问日志保存路径
    #access_log /var/log/nginx/access.log access;
}

Tagged: , , , ,

Comments are closed.