nginx反代nas设备网站

1,868次阅读
没有评论

# You may add here your
# server {
# …
# }
# statements for each of your virtual hosts to this file

##
# You should look at the following URL’s in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##
# 配置临时目录、缓存路径(注意要先建立这 2 个目录,要在同一个硬盘分区,注意权限)

proxy_temp_file_write_size 128k;
proxy_temp_path /home/cache/nginx_proxy_temp;
proxy_cache_path /home/cache/nginx_proxy_cache_hxs levels=1:2 keys_zone=cache_hxs:50m inactive=3d max_size=2g;
#levels: 指定该缓存空间有两层 hash 目录,第一层目录为 1 个字母,第二层为 2 个字母。
#inactive=1d: 如果 1 天内该资源没有被访问则删除;inactive=30m: 如果 30 分钟内该资源没有被访问则删除
#keys_zone=cache_one:50m 指为缓存空间起个名字,这里取名为“cache_one”,内存缓存空间的大小为 50MB
#max_size=2g 指硬盘缓存空间的大小为 2G

upstream ddns {
dynamic_resolve fallback=stale fail_timeout=30s;
server ddns1.oicp.net:9580;
server ddns2.oicp.net:9580;
server 35.199.XXX.XXX:80 backup;
check interval=3000 rise=3 fall=3 timeout=1000 default_down=false type=tcp;
}

server {
listen 80;

server_name www.hxs.pub;

location / {
proxy_pass http://ddns;
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;
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
client_max_body_size 8m;
}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$ {
proxy_cache_key $host$uri$is_args$args;
proxy_cache cache_hxs;
proxy_cache_valid 200 304 3d; #正常状态缓存时间 1 天
proxy_cache_valid 301 3d;
proxy_cache_valid 500 502 503 504 0s;
proxy_cache_valid any 10s; #其他的缓存多长时间,或者不缓存
proxy_cache_min_uses 1; #只要同一个 url,不管间隔多久,总次数访问到达 1 次,就开始缓存。
# proxy_cache_bypass $cookie_nocache $arg_nocache$arg_comment; # 如果任何一个参数值不为空,或者不等于 0,nginx 就不会查找缓存,直接进行代理转发
expires 2d;
proxy_pass http://ddns;
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;
}
}

server {
listen 80;
server_name hxs.pub;
rewrite ^/(.*) http://www.hxs.pub/$1 permanent;
}

 

 

附件:

 

nginx

正文完
 0
评论(没有评论)
验证码