美文网首页
阿里云oss上传服务 nginx 反向代理 需要配置两个域名

阿里云oss上传服务 nginx 反向代理 需要配置两个域名

作者: yichen_china | 来源:发表于2021-11-18 18:22 被阅读0次

nginx配置如下

#预览文件配置域名
# 配置文件 前边增加BucketName前缀
server
{
    listen 80;
    server_name oss.zt.lnby.com;
    client_max_body_size 20M;
    #PROXY-START/
location  ~* \.(gif|png|jpg|jpeg|css|js|woff|woff2)$
{
#前边增加BucketName前缀lnby-zt.
    proxy_pass http://lnby-zt.oss-cn-zhangjiakou-internal.aliyuncs.com;
    proxy_set_header Host lnby-zt.oss-cn-zhangjiakou-internal.aliyuncs.com;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
    expires 12h;
}
location /{
    proxy_pass http://lnby-zt.oss-cn-zhangjiakou-internal.aliyuncs.com;
    proxy_set_header Host lnby-zt.oss-cn-zhangjiakou-internal.aliyuncs.com;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
    add_header X-Cache $upstream_cache_status;
    #Set Nginx Cache
    add_header Cache-Control no-cache;
}

    #PROXY-START/
    #引用反向代理规则,注释后配置的反向代理将无效
    #  include /www/server/panel/vhost/nginx/proxy/oss.zt.lnby.com/*.conf;
     # include enable-php-00.conf;
    #PHP-INFO-END
    
    #REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
    include /www/server/panel/vhost/rewrite/oss.zt.lnby.com.conf;
    #REWRITE-END
    
    #禁止访问的文件或目录
    location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
    {
        return 404;
    }
    
    #一键申请SSL证书验证目录相关设置
    location ~ \.well-known{
        allow all;
    }
    
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires      30d;
        error_log /dev/null;
        access_log /dev/null;
    }
    location ~ .*\.(js|css)?$
    {
        expires      12h;
        error_log /dev/null;
        access_log /dev/null;
    }
    access_log  /www/wwwlogs/oss.zt.lnby.com.log;
    error_log  /www/wwwlogs/oss.zt.lnby.com.error.log;
}
#BINDING-lnby-zt.oss.zt.lnby.com-START
#上传文件配置域名
# 配置文件 EndPoint=oss.zt.lnby.com 的时候上传会自动在前边增加BucketName前缀
#OSS ossClient = new OSSClientBuilder().build(EndPoint, AccessKeyID, AccessKeySecret);
server
{
    listen 80;
    server_name lnby-zt.oss.zt.lnby.com;
    client_max_body_size 20M;
    index index.php index.html index.htm default.php default.htm default.html;
    root /www/wwwroot/oss.zt.lnby.com/lnby-zt;
    #PROXY-START/
location  ~* \.(gif|png|jpg|jpeg|css|js|woff|woff2)$
{
    proxy_pass http://lnby-zt.oss-cn-zhangjiakou-internal.aliyuncs.com;
    proxy_set_header Host lnby-zt.oss-cn-zhangjiakou-internal.aliyuncs.com;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
    expires 12h;
}
location /
{
    proxy_pass http://lnby-zt.oss-cn-zhangjiakou-internal.aliyuncs.com;
    proxy_set_header Host lnby-zt.oss-cn-zhangjiakou-internal.aliyuncs.com;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
    add_header X-Cache $upstream_cache_status;
    #Set Nginx Cache
    
        add_header Cache-Control no-cache;
}

    include enable-php-00.conf;
    include /www/server/panel/vhost/rewrite/oss.zt.lnby.com.conf;
    #禁止访问的文件或目录
    location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
    {
        return 404;
    }
    
    #一键申请SSL证书验证目录相关设置
    location ~ \.well-known{
        allow all;
    }
    
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires      30d;
        error_log /dev/null;
        access_log /dev/null; 
    }
    location ~ .*\.(js|css)?$
    {
        expires      12h;
        error_log /dev/null;
        access_log /dev/null; 
    }
    access_log /www/wwwlogs/oss.zt.lnby.com.log;
    error_log  /www/wwwlogs/oss.zt.lnby.com.error.log;
}
#BINDING-lnby-zt.oss.zt.lnby.com-END

如果报错405 可能是代理的类型出问题了 location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$

相关文章

网友评论

      本文标题:阿里云oss上传服务 nginx 反向代理 需要配置两个域名

      本文链接:https://www.haomeiwen.com/subject/ichjtrtx.html