nginx虚拟主机配置

server {
        listen 80;
        server_name www.xxx.com;

        access_log /path/to/logs/access.log;
        error_log /path/to/error/logs/error.log notice;

        rewrite ^/app\.php/?(.*)$ /$1 permanent;
        #rewrite ^/(.*)/$ /$1 permanent;

        root   /srv/www/xxx.com/web;

      #  error_page 500 502 504 /500.html;


        #location ~ .*\.(js|css|gif|jpg|jpeg|png|bmp|swf|ico)$
        #{
        #       add_header Cache-Control "public";
        #       expires 30d;
        #       access_log off;
        #}

        #location ~ .*\.(js|css|gif|jpg|jpeg|png|bmp|swf|ico)$
        #{
        #        proxy_set_header X-Real-IP $remote_addr;
        #        proxy_set_header X-Forwarded-For $remote_addr;
        #        proxy_set_header Host $http_host;
        #        proxy_pass_header Set-Cookie;
        #        proxy_pass http://10.105.11.135;
        #}

        location /admin {
                auth_basic "Restricted Content";
                auth_basic_user_file /etc/nginx/sites-enabled/.htpasswd;
                try_files $uri @rewriteapp;
        }

        location / {
                index app.php;
                try_files $uri @rewriteapp;
        }

        location @rewriteapp {
        rewrite ^(.*)$ /app.php/$1 last;
        }

        location ~ \.php {
            #    fastcgi_cache fcgi;
                fastcgi_cache_valid 200 302 1m;               #对HTTP状态是200与302只缓存一分钟
                fastcgi_cache_valid 404 500 502 503 504 0s;   #不缓存相应HTTP状态的返回
                fastcgi_cache_valid any 1m;                   #缓存所有的请求1分钟
                fastcgi_cache_min_uses 1;                     #只要被请求1次就会被缓存
                fastcgi_cache_use_stale error timeout invalid_header http_500 http_503 updating;    #过期条件
                fastcgi_buffer_size 64k;                 #nginx从fpm是一部分一部分获取数据的,nginx先拿满64K再去拿一次
                fastcgi_buffers 4 64k;                   #缓存个数
                fastcgi_busy_buffers_size 128k;          #限制向用户发送请求使用的buffer这样其它部分的buffer还可以做其它的事情

                fastcgi_pass  unix:/run/php5-fpm.sock;    #将请求转发给fpm
                fastcgi_split_path_info ^(.+\.php)(/.*)$; #用正则表达式匹配两部分,一部分为$fastcgi_path_info,另一部分为$fastcgi_path_info
                include /etc/nginx/fastcgi_params;        #引入fastcgi_params的配置文件
                fastcgi_param SCRIPT_FILENAME   $document_root$fastcgi_script_name;  #入口文件
                fastcgi_param HTTPS             off;
        }

}

 

posted @ 2016-05-10 15:04  S大好人S  阅读(183)  评论(0编辑  收藏  举报