llcong 发表于 2018-11-8 12:31:30

nginx实现静态页面,图片分离

#vi /usr/local/nginx/conf/nginx.conf  user nginx nginx;
  worker_processes1;
  events {
  worker_connections1024;
  }
  http {
  include       mime.types;
  default_typeapplication/octet-stream;
  sendfile      on;
  keepalive_timeout65;
  upstream webservs {
  server 172.16.100.6 weight=1;
  server 172.16.100.7 weight=1;
  }
  server {
  listen       8082;
  server_namelocalhost;
  index index.html index.htm index.php;
  rewrite ^/$ /zabbix/index.php permanent;
  location / {
  proxy_pass webservs;
  proxy_set_header X-Real-IP $remote_addr;
  }
  location /zabbix {
  root /var/www;
  fastcgi_pass 127.0.0.1:8000;
  fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  include fastcgi_params;
  }
  #配置Nginx动静分离,定义的静态页面直接从zabbix发布目录读取(root /opt/nginx-1.4.7/html/resources;)。
  location ~* ^/zabbix/.+\.(ico|gif|jpg|jpeg|html|htm|png|css|bmp|js|svg)$ {
  root         /var/www;
  #expires定义用户浏览器缓存的时间为7天,如果静态页面不常更新,可以设置更长,这样可以节省带宽和缓解服务器的压力
  expires      7d;
  }
  #配置静态图片页面
  location ~ .*\.(gif|jpg|jpeg|png)$ {
  expires 24h;       #设置浏览器过期时间
  root /home/picimages/; #指定图片存放路径
  access_log /usr/local/nginx/logs/picimages.log; #图片日志路径
  proxy_store on;      #开启缓存机制
  proxy_store_access user:rw group:rw all:rw;    #缓存读写规则
  proxy_temp_path         /home/picimages/; #代理临时路径
  proxy_redirect          off;
  proxy_set_header      Host 127.0.0.1;
  client_max_body_size    10m;
  client_body_buffer_size 1280k;
  proxy_connect_timeout   900;
  proxy_send_timeout      900;
  proxy_read_timeout      900;
  proxy_buffer_size       40k;
  proxy_buffers         40 320k;
  proxy_busy_buffers_size 640k;
  proxy_temp_file_write_size 640k;
  if ( !-e $request_filename)      ##正则表达式,匹配缓存目录中的文件与源文件是否存在,当访问的文件和目录不存在时,重定向到某个网站地址或文件
  proxy_passhttp://127.0.0.1:8082;      #代理访问地址
  }
  }
  location /citizen {
  proxy_pass http://172.28.3.103:9081;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header Host $host:$server_port;
  }
  error_page   500 502 503 504/50x.html;
  location = /50x.html {
  root   html;
  }
  }
  }

页: [1]
查看完整版本: nginx实现静态页面,图片分离