Alex的博客

本博客的文章均为原创,是本人从事行业多年来所遇见一些小问题的解决心得,希望可以帮助到大家!



nginx配置文件整理[备忘]

/etc/nginx/nginx.conf

###############################

user  nginx;
worker_processes  auto;
worker_rlimit_nofile 65535;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


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


http {


    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
   # client_max_body_size 20m;
    log_format  main  '$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  main;

    #sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  10;

    #gzip  on;

############################################################
  server_names_hash_bucket_size 128;
  client_header_buffer_size 32k;
  large_client_header_buffers 4 32k;
  client_max_body_size 8m;
  server_tokens off;
  sendfile on;
  tcp_nopush     on;
  keepalive_timeout 60;
  #tcp_nodelay on;
    client_header_timeout 10;
    client_body_timeout 10;
    reset_timedout_connection on;
    send_timeout 10;
        tcp_nodelay on;
    open_file_cache max=65535 inactive=60s;
    open_file_cache_valid 80s;
    open_file_cache_min_uses 1;
    autoindex off;
    limit_conn_zone $binary_remote_addr zone=addr:5m;
    limit_conn addr 100;



  fastcgi_connect_timeout 300;
  fastcgi_send_timeout 300;
  fastcgi_read_timeout 300;
  fastcgi_buffer_size 64k;
  fastcgi_buffers 2 256k;
  fastcgi_busy_buffers_size 256k;
  fastcgi_temp_file_write_size 256k;

  gzip    on;
  gzip_min_length   1k;
  gzip_buffers   4 8k;
  gzip_http_version  1.1;
  gzip_types   text/plain application/x-javascript text/css  application/xml;
  gzip_disable "MSIE [1-6]\.";


##########################################################################
#反向代理缓存
    #client_max_body_size 10m;
    client_body_buffer_size 128k;

    proxy_connect_timeout 300;
    proxy_send_timeout 300;
    proxy_read_timeout 300;
    proxy_buffer_size 64k;
    proxy_buffers 4 512k;
    proxy_busy_buffers_size 512k;
    proxy_temp_file_write_size 512k;
    proxy_temp_path   /var/data/cache/temp;
    proxy_cache_path  /var/data/cache/path levels=1:2 keys_zone=cache_one:2000m inactive=3d max_size=50g;

    proxy_redirect off;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;


###内替换

#sub_filter      </html>   'alex</html>';

#如果为off表示全文替换 on表示只替换一次

#  sub_filter_once off/on;
#  sub_filter_types text/html;


    include /etc/nginx/conf.d/*.conf;

server {
    listen       80  default_server;
    server_name  _;
    return       404;
}

}


//创建公共内容调用目录

mkdir /etc/nginx/public

创建公共php调用部分

vi /etc/nginx/public/php-fpm

内容:

location ~ \.php$ {
    try_files                   $uri = 404;
    fastcgi_intercept_errors    on;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /$document_root$fastcgi_script_name;

  #php优化

    fastcgi_split_path_info ^(.+\.php)(.*)$;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO  $fastcgi_path_info;
    fastcgi_param PATH_TRANSLATED  $document_root$fastcgi_path_info;

    include        fastcgi_params;
}


虚拟主机配置文件

/etc/nginx/conf.d/default

server {
    listen       80;
    server_name  localhost;
    root         /var/www/html/default;

###下面的可以选择性的增减

####CI index.php隐藏

if (!-e $request_filename) {
         rewrite ^/(.*)$ /index.php?$1 last;
         break;
     }

#######设置文件类型缓存时间

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp3|wma)$
        {
                expires      30d;
        }
        location ~ .*\.(js|css)$
        {
                expires      12h;
        }

####重定向url路径

location /robots.txt {
rewrite /robots.txt /wrobots.txt last;
}

#######定义日志路径

error_log  /var/log/nginx/lexue_error.log;
 access_log /var/log/nginx/lexue_access.log;

#######url重定向  [把不带www的重定向到www]

if ($host = nwiedu.com) {
        rewrite ^(.*)$ http://www.nwiedu.com permanent;
    }

#####下面是必须的

    location / {
        index  index.html index.htm index.php;
        include     /etc/nginx/public/php-fpm;
}
}

浏览503  评论0  Alex于 2016-12-13 13:40
发言