Relatives SAAS company is doing electronic business systems, there is a demand, customers need to access by domain host Ali cloud resources in the OSS domain folder.
For example, user access
http://mall.shop.com/base.css, in fact, access http://aliyun-oss.aliyuncs.com/mall.shop.com/base.css
HTTP: //www.mall. com / banner.jpg, in fact, is to visit http://aliyun-oss.aliyuncs.com/www.mall.com/banner.jpg
upstream sh_aliyun {
server aliyun-oss.aliyuncs.com:80 weight=10 max_fails=3 fail_timeout=10s;
}
server {
listen 0.0.0.0:80;
server_name _;
location / {
proxy_redirect off ;
proxy_set_header Host aliyun-oss.aliyuncs.com; #填写OSS访问域名
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Real-Port $remote_port;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 50m;
client_body_buffer_size 256k;
proxy_connect_timeout 30;
proxy_send_timeout 30;
proxy_read_timeout 60;
proxy_buffer_size 256k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 256k;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_404;
proxy_max_temp_file_size 128m;
proxy_pass http://sh_aliyun/$host$request_uri; #这里填写变量$host,是访问的主机名,$request_uri完整的请求参数
}
}
Stepped pit:
direct use
proxy_pass http://aliyun-oss.aliyuncs.com/$host$request_uri ; has requested all 502
proxy_pass http://106.14.228.198/$host$request_uri ; this is possible
Therefore it concluded:
proxy_pass if variables exist, can not be used in the form of domain names, only with upstream