#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
#(启用 gzip 压缩功能)
gzip_proxied any;
#(nginx 做前端代理时启用该选项,表示无论后端服务器的headers头返回什么信息,都无条件启用压缩)
gzip_min_length 1024;
#(最小压缩的页面,如果页面过于小,可能会越压越大,这里规定大于1K的页面才启用压缩)
gzip_buffers 4 8k;
#(设置系统获取几个单位的缓存用于存储gzip的压缩结果数据流)
gzip_comp_level 3;
#(压缩级别,1压缩比最小处理速度最快,9压缩比最大但处理最慢,同时也最消耗CPU,一般设置为3就可以了)
gzip_types text/plain application/x-javascript text/css text/javascript application/x-httpd-php image/jpeg image/gif image/png;
#(什么类型的页面或文档启用压缩)
# gzip_types text/plain application/x-javascript text/css text/javascript application/x-httpd-php image/jpeg image/gif image/png;
#图片
#错误页面
fastcgi_intercept_errors on;
#nginx还有一种缓存proxy_cache,它在设计上比proxy_store 更先进,采用内存+硬盘方式缓存,可以设置缓存大小和缓存过期。
proxy_connect_timeout 5;
proxy_read_timeout 60;
proxy_send_timeout 5;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
proxy_temp_path C:/nginx-1.7.7/temp/proxy_temp;
proxy_cache_path C:/nginx-1.7.7/temp/ levels=1:2 keys_zone=imgcache:100m inactive=1d max_size=10g;
#监听的节点
upstream mysite{
server 127.0.0.1:81 weight=11;
server 192.168.12.1:83 weight=10;
# ip_hash;
# server 127.0.0.1:81 weight=11;
# server 192.168.12.1:83 weight=10;
}
#listen监听的端口,server_name服务器名称,监听那个服务器那个端口
server {
listen 80;
server_name www.24yb.com;
#charset koi8-r;
#access_log logs/host.access.log main;
error_page 404 /404.aspx;
location / {
proxy_pass http://mysite;
proxy_redirect default;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#静态文件缓存方式一(需定期清理)
#location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|html|htm|css)$ {
# log_not_found off;
# expires 7d ;
# root C:/nginx-1.7.7/file;
# access_log off;
# proxy_store on;
# proxy_store_access user:rw group:rw all:rw;
# if ( !-e $request_filename) {
# proxy_pass http://mysite;
# }
#}
#静态文件缓存方式二
#将会使用一块最大100M的共享内存,用于硬盘上的文件索引,包括文件名和请求次数,每个文件在1天内若不活跃(无请求)则从硬盘上淘汰,硬盘缓存最大10G,满了则根据LRU算法自动清除缓存。
location ~* ^.+\.(js|ico|gif|jpg|jpeg|png|html|htm)$ {
log_not_found off;
access_log off;
expires 7d;
proxy_pass http://mysite;
proxy_cache imgcache;
proxy_cache_valid 200 302 1d;
proxy_cache_valid 404 10m;
proxy_cache_valid any 1h;
proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
}
}
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# 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 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
问题:原来正常,加了缓存这块后启动不了
错误信息:
2014/12/03 17:27:45 [emerg] 8824#7584: shared zone "imgcache" has no equal addresses: 02EF0000 vs 02FA0000
2014/12/03 17:27:45 [alert] 10320#9396: worker process 8824 exited with code 1
2014/12/03 17:30:17 [emerg] 6916#10492: shared zone "imgcache" has no equal addresses: 02CF0000 vs 02E40000
2014/12/03 17:30:17 [alert] 5160#11196: worker process 6916 exited with code 1
proxy_cache imgcache; 这里的imgcache 应该是个本地地址吧
估计你是在windows下使用nginx吧, 你把内存设置大一点 然后在重启nginx, 如果不行就再设置大一点在重启nginx,重复几次就启动了。我发现在windows下nginx只要使用了内存设置就会这样,多试几次。
你好 请问你说的内存是指什么的内存呀