Nginx上媒体链接的Http 404错误

时间:2018-05-24 10:18:16

标签: nginx http-status-code-404 reverse-proxy cdn

我需要显示来自我的拥有nginx网络服务器的vps的外部cdn的媒体(图像和视频)链接。我在nginx.conf上的摘要配置:



upstream video_balancer {
        server                  res.cloudinary.com;
        }

server {
        listen                  80; 
        server_name             video.XXXXX.com;  
        return                  301      https://$host$request_uri; 
        }

server {
        listen                  443      ssl; 
        ssl                     on;
        server_name             video.XXXXX.com;
        root                    /var/www/video/html/;
        ssl_ciphers             'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
        ssl_certificate         /etc/nginx/ssl/XXXXX.crt;
        ssl_certificate_key     /etc/nginx/ssl/XXXXX.key;
        ssl_session_cache       shared:SSL:1m;
        ssl_prefer_server_ciphers on;
        ssl_protocols           TLSv1 TLSv1.1 TLSv1.2;
        ssl_verify_client       off;
                                                                                                       
    location / {    
        try_files               $uri $uri/ 404;
        proxy_method            GET;                                                                                                
        proxy_redirect          off;                                                                                                
        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_set_header        X-Forwarded-Proto       $scheme;                                                                    
        proxy_set_header        X-Forwarded-Port        443;                                                                        
        proxy_set_header        X-Forwarded-Ssl         on;                                                                         
        proxy_set_header        X-Forwarded-HTTPS       "on";                                                                       
        proxy_ssl_session_reuse off;                                                                                                
        proxy_http_version      1.1;                                                                                                
        proxy_pass              http://video_balancer$request_uri;                                                           
        }                                                                                                                           
} 




当我在链接下面尝试示例时,我收到404 Not Found错误:

https://video.XXXXX.com/mediaclub/video/upload/v1527154870/news.mp4

和相关的访问日志:

X.X.X.X - - [24/May/2018:14:53:42 +0430] "GET /mediaclub/video/upload/v1527154870/news.mp4 HTTP/1.1" 404 200 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36" "-"

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

我通过重定向解决了这个问题,将来会遇到同样的问题:

location ^~ /path/ {
          rewrite ^ http://res.cloudinary.com$request_uri? permanent;
}