0

阿里云OSS之Nginx反向代理配置

nginx配置

设置代理

upstream ossproxy{
server zcpcimgs.oss-cn-beijing.aliyuncs.com;
}

配置代理

server {
listen 80;
server_name zc2019.com;

location /data {
proxy_pass http://ossproxy;
proxy_redirect off;
proxy_set_header Host zcpcimgs.oss-cn-beijing.aliyuncs.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_max_temp_file_size 0;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}

location / {
# root html;
# index index.html index.htm;
proxy_pass http://zcjfweb;
# 真实信息
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 100M;
proxy_read_timeout 30000;
proxy_send_timeout 75s;
#proxy_redirect off;
#proxy_pass_header Set-Cookie;
#proxy_hide_header X-Powered-By;
#proxy_hide_header X-Mod-Pagespeed;
#proxy_ignore_client_abort off;
#proxy_cache_valid any 10m;
#proxy_connect_timeout 75s;
#proxy_read_timeout 75s;
#proxy_send_timeout 75s;
}

#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_pass https://www.baidu.com/;
#}

error_page 500 502 503 504 /no_server.html;
location = /no_server.html {
# root html;
proxy_pass http://127.0.0.1:88/;
}

# 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;
#}

}

 

 

其他

location ^~ /resource/images/oss { proxy_pass http://bucket名.oss-cn-shenzhen-internal.aliyuncs.com; }

意思就是匹配到链接里有/resource/images/oss这样的后缀以后直接去相应的oss域名上请求资源

 

#配置Nginx动静分离,定义的静态页面直接从Nginx发布目录读取。

       location ~ .*\.(gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
            root /usr/upload; # 你自己的静态地址
                   #expires定义用户浏览器缓存的时间为7天,如果静态页面不常更新,可以设置更长,这样可以节省带宽和缓解服务器的压力
            expires      7d;
        }
更多Nginx配置参考:
https://www.cnblogs.com/sign-ptk/p/6723048.html
https://blog.csdn.net/qq_33862644/article/details/79337348
https://www.cnblogs.com/coder-yoyo/p/6346595.html
https://www.cnblogs.com/onmyway20xx/p/3664302.html
https://www.cnblogs.com/gpfeisoft/p/4823919.html

天边的星星