日存档: 26 12 月, 2017

curl 常用用法

-F,以multipart/form-data的方式发送POST请求

curl -F "key=value" -F "filename=@file" http://xxx/upload

-H, 添加Header内容

curl -H "Content-Type: application/json" -X POST -d '{"username":"xyz","password":"xyz"}' http://xxx/api

-d, 以application/x-www-url-encoded格式上传参数

curl -d "action=dosth" -d "name=xxx" http://xxx/api

-o, 输出到文件,可以指定下载文件

curl http://xxx/xxx -o file

nginx proxy_cache 静态资源缓存

直接贴上nginx.conf

#cache begin
    proxy_buffering on;
    proxy_cache_valid any 10m;
    proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=nginxcache:8m max_size=10g inactive=30d;
    proxy_temp_path /data/nginx/temp;
    proxy_buffer_size 4k;
    proxy_buffers 100 8k;
#cache end

server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  tixbay.net;
        root         /data/nginx/www;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location ~ .*\.(jpg|jpeg|png|gif|js|css)?$ { #一般只缓存静态资源
                proxy_cache nginxcache; #与keys_zone对应
                proxy_cache_valid  200 206 304 301 302 10d;
                proxy_cache_key $scheme$uri$is_args$args; #缓存key
                proxy_redirect off;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header REMOTE-HOST $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                client_max_body_size 100m;
                proxy_pass http://tunnelhome;
        }

        location / { #其他默认处理
                proxy_redirect off;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header REMOTE-HOST $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                client_max_body_size 100m;
                proxy_pass http://tunnelhome;
        }
}