nginx实战

以下nginx配置是最新手机游戏网 正在使用的配置

访问速度非常优秀,对nginx进行了优化

希望对您有些帮助

 

user www www;
worker_processes 8;
worker_cpu_affinity 0001 0010 0100 1000 0001 0010 0100 1000;
worker_rlimit_nofile 65535;
error_log /usr/local/nginx/logs/error.log crit;
pid /usr/local/nginx/nginx.pid;


events {
    use epoll;
    worker_connections 65535;
}


http {

 

    include       mime.types;
    default_type  application/octet-stream;
    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 8m;
    sendfile on;
    tcp_nopush     on;
    keepalive_timeout 60;
    tcp_nodelay on;
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;
    fastcgi_intercept_errors on;
    gzip on;
    gzip_min_length  1k;
    gzip_buffers     4 16k;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_types       text/plain application/x-javascript text/css application/xml;
    gzip_vary on;

 

 

 

 


    server {
        listen       80;
        server_name  www.19195.cn 19195.cn;
        if ($host != 'www.19195.cn' ) {
           rewrite ^/(.*)$ http://www.19195.cn/$1 permanent;
        }
        index index.html index.htm index.php;
        root  /www/ws/doubanapp;
        error_page 404 /404.html;
        error_page 403 /404.html;
        location ~ .*\.(php|php5)?$
        {
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi.conf;
         }
        location / {
             rewrite ^/search/(.*)/([0-9]+).html$ /index.php?s=/Home-vod-search-wd-$1-p-$2 last;
             rewrite ^/play/([0-9]+)/([0-9]+)/([0-9]+).html$ /index.php?s=/Home-vod-play-id-$1-sid-$2-pid-$3 last;
             rewrite ^/vod-(.*)\.html$ /index.php?s=/Home-vod-$1 last;
             rewrite ^/news-(.*)$ /index.php?s=/Home-news-$1 last;
             rewrite ^special-(.*)$ /index.php?s=/Home-special-$1 last;
             rewrite ^/tag-(.*)$ /index.php?s=/Home-tag-$1 last;
             rewrite ^/gb-(.*)$ /index.php?s=/Home-gb-$1 last;
             rewrite ^/cm-(.*)$ /index.php?s=/Home-cm-$1 last;
             rewrite ^/map-(.*)$ /index.php?s=/Home-map-$1 last;
             rewrite ^/my-(.*)$ /index.php?s=/Home-my-$1 last;
             rewrite ^/Tpl/(.*)/Home/(.*).html$ /index.php last;
             rewrite ^/MvTop9/(.*)$ /detail/live.html last;
             rewrite ^/list/([0-9]+)/([0-9]+).html$ /index.php?s=/Home-vod-show-id-$1-p-$2 last;
            rewrite ^/channel$ /index.php?s=/Home-vod-show-id-1-p-1 last;
            rewrite ^/teleplay$ /index.php?s=/Home-vod-show-id-2-p-1 last;
           }

         location ~(favicon.ico) {
             log_not_found off;
             expires 99d;
             break;
         }

         location ~(robots.txt) {
              log_not_found off;
              expires 7d;
              break;
         }
         location ~ ^/data {
             deny all;
         }
         location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css|zip|rar)$
         {

            access_log   off;
            expires      30d;
         }
         location ~ .*\.(js|css)?$
         {

            access_log   off;
            expires      1h;
         }


          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  /ss/wws/19195_access.log  access;
              error_page  404  /404.html;
      }

 

 


    server {
        listen       80;
        server_name  www.tiaoju.com tiaoju.com;
        if ($host != 'www.tiaoju.com' ) {
           rewrite ^/(.*)$ http://www.tiaoju.com/$1 permanent;
        }
        index index.html index.htm index.php;
        root  /www/wws/tiaoju;
        error_page 404 /404.html;
        error_page 403 /404.html;
        location ~ .*\.(php|php5)?$
        {
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi.conf;
         }
        location / {
             rewrite ^/guochan$ /index.php?s=/Home-vod-show-id-15-p-1 last;
rewrite ^/tvb$ /index.php?s=/Home-vod-show-id-16-p-1 last;
rewrite ^/oumei$ /index.php?s=/Home-vod-show-id-17-p-1 last;
rewrite ^/rihan$ /index.php?s=/Home-vod-show-id-18-p-1 last;
rewrite ^/haiwai$ /index.php?s=/Home-vod-show-id-19-p-1 last;
rewrite ^/dongzuo$ /index.php?s=/Home-vod-show-id-8-p-1 last;
rewrite ^/xiju$ /index.php?s=/Home-vod-show-id-9-p-1 last;
           }

         location ~(favicon.ico) {
             log_not_found off;
             expires 99d;
             break;
         }

         location ~(robots.txt) {
              log_not_found off;
              expires 7d;
              break;
         }
         location ~ ^/data {
             deny all;
         }
         location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css|zip|rar)$
         {

            access_log   off;
            expires      30d;
         }
         location ~ .*\.(js|css)?$
         {

            access_log   off;
            expires      1h;
         }


          log_format  access23  '$remote_addr - $remote_user [$time_local] "$request" '
              '$status $body_bytes_sent "$http_referer" '
              '"$http_user_agent" $http_x_forwarded_for';
             access_log  /sss/www/tiaoju_access.log  access;
              error_page  404  /404.html;
      }
      server{
           listen 80 default;
           server_name _;
           rewrite ^(.*) http://www.19195.cn permanent;
      }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443;
    #    server_name  localhost;

    #    ssl                  on;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_timeout  5m;

    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers   on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

你可能感兴趣的:(nginx)