ubuntu下nginx配置文件

一、nginx.conf 文件,路徑爲:/etc/nginx/nginx.confjavascript

#使用的用戶和組
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;
#    }
#}

二、default 服務主機配置文件,路徑爲:/etc/nginx/sites-available/defaultphp

#主機
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 」 == 「 location ~ \.php($|/) 」
   #第一句的意思是若是請求字符中匹配到「 .php 」字符,就交給php解析器處理
   #第二句的意思是若是請求字符中匹配到以「 .php 」字符爲結尾的或 「 .php/ 」 字符,就交給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;
}
相關文章
相關標籤/搜索