侧边栏壁纸
博主头像
cn2linux博主等级

行动起来,活在当下

  • 累计撰写 128 篇文章
  • 累计创建 1 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

NGINX-配置文件

NGINX CONF配置

user  www www;
worker_processes auto;
error_log  /var/log/nginx_error.log  crit;
worker_rlimit_nofile 204800;

events {
        use epoll;
        worker_connections 65535;
        multi_accept on;
 }

http {
        include       mime.types;
        default_type  application/octet-stream;
        client_header_buffer_size 32k;
        large_client_header_buffers 4 32k;
        client_max_body_size 50m;
        sendfile   on;
        tcp_nopush on;

        proxy_connect_timeout 10s;
        proxy_read_timeout 60s;
        proxy_send_timeout 60s;
        proxy_buffering on;
        proxy_buffer_size 32k;
        proxy_buffers 32 1m;
        proxy_busy_buffers_size 2m;
        proxy_temp_file_write_size  1m;
        server_names_hash_bucket_size 1280;
        proxy_headers_hash_max_size 51200;
        proxy_headers_hash_bucket_size 6400;

        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 256k;
        gzip on;
        gzip_min_length  1k;
        gzip_buffers     4 16k;
        gzip_http_version 1.1;
        gzip_comp_level 4;

        gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
        gzip_vary on;
        gzip_proxied   expired no-cache no-store private auth;
        gzip_disable   "MSIE [1-6]\.";
        server_tokens off;
        underscores_in_headers on ;
        # 日志格式化
        log_format mainJson escape=json  '{'
                 '"server_name": "localhost",'
                  '"time_local": "fmt_localtime" ,'
                  '"http_host": "http_host",'
                  '"remote_addr": "remote_addr",'
                  '"http_x_forwarded_for": "http_x_forwarded_for",'
                  '"http_x_real_ip": "http_x_real_ip",'
                  '"request_time": "request_time",'
                  '"upstream_addr": "upstream_addr",'
                  '"upstream_response_time": "upstream_response_time",'
                  '"upstream_bytes_sent": "upstream_bytes_sent",'
                  '"upstream_bytes_received": "upstream_bytes_received",'
                  '"upstream_cache_status": "upstream_cache_status",'
                  '"request": "request",'
                  '"status": "status,"'
                  '"body_bytes_sent": "body_bytes_sent",'
                  '"http_referer": "http_referer",'
                  '"http_user_agent": "http_user_agent"'
                  '}';

              map hostfmt_localtime {
                default '';
              }
              log_by_lua_block {
                ngx.var.fmt_localtime = ngx.localtime();
              }
            error_page 403 =404 /40X.html;
        access_log /home/wwwlogs/nginx-access.log mainJson;
        include /data/vhost/*.conf;
}

NGINX VHOST 配置

server {
  listen       80 ;
  server_name  domain.com www.domain.com;
  root    /data/wwwroot/;
  index   index.html index.htm index.php;

  location / {
    if (!-e $request_filename) {
      rewrite ^(.*)$ /index.php$1 last;
    }
  }
  location ~ .*\.php(\/.*)*$ {
    include fastcgi.conf;
    set $path_info "";
    set $real_script_name $fastcgi_script_name;
    if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
    set $real_script_name $1;
    set $path_info $2;
    }
    fastcgi_pass  127.0.0.1:9000;
    fastcgi_param  PATH_INFO  $path_info;
    fastcgi_param  SCRIPT_NAME     $fastcgi_script_name;
    fastcgi_param  SCRIPT_FILENAME   $document_root$real_script_name;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 256 16k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
   #This file is present on Debian systems..
    include fastcgi_params;
    }
  location ~ .*\.(gif|jpg|jpeg|png||png|bmp)$ {
        expires 1d;
  }
  access_log /usr/local/nginx/logs/www_domain.log combined;
 }

NGINX PROXY 配置

upstream  backend  {
  server   127.0.0.1:8080  max_fails=3  fail_timeout=30s;
}

server {
  listen 80;
  server_name work.niknk.com ;
location / {
  proxy_pass http://backend;
  proxy_cache cache001;
  proxy_cache_key $host$uri$is_args$args; 
  proxy_set_header Host $host;
  proxy_set_header X-Forwarded-For $remote_addr;
  proxy_cache_valid 200 304 12h;
  expires 2d;
}
location ~ .*\.(php|jsp|cgi|asp|aspx|flv|swf|xml)?$ {
  proxy_set_header Host $host;
  proxy_set_header X-Forwarded-For $remote_addr;
  proxy_pass http://backend;
}
location ~ /purge(/.*) {
  proxy_cache_purge cache001 $host$1$is_args$args;
}
  access_log off;
}

0

评论区