nginx 代理通过 nginx 1.1.19

nginx 代理通过 nginx 1.1.19

我正在尝试让暂存服务器上找不到的图像自动从生产服务器加载。我在 nginx 1.6.2 上使用以下配置本地测试了此操作:一切按预期运行

server {
    root /var/www/html/test;
    index index.html index.htm;

    # Make site accessible from http://localhost/
    server_name nginx1.local;

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ @fallback;
            # Uncomment to enable naxsi on this location
            # include /etc/nginx/naxsi.rules
    }

    location @fallback{
            proxy_pass http://nginx2.local;
    }

}

但是在我们的生产服务器中我无法让它工作。生产运行 nginx 1.1.19,我想知道从那时起 proxy_pass 是否发生了变化。请知悉,我是这份工作的新手,目前无法为所有过时的东西负责。

server {
    # Specify default_server here as catch-all (sites not in any other 'server' blocks)
    listen   80; # ipv4
    #listen   [::]:80 default ipv6only=on; # ipv6

    root /var/www/testing/public;
    index index.html index.htm /index.html; # Ending /index.html is a sort of 'internal redirect' because of the starting slash

    # Set to "" (empty) as catch-all (in conjuction with listen directive)
    server_name "testing.media.foo.com";

    ##
    # Logging Settings
    ##
    access_log /var/www/testing/logs/access.log;
    error_log /var/www/testing/logs/error.log;

    # Specify a charset
    charset utf-8;

    # Implement filename-based cache busting ala h5bp
    #include /etc/nginx/h5bpconf/cache-busting.conf;
    rewrite ^/(.+)\.v(\d+)\.(js|css|png|jpg|jpeg|gif)$ /$1.$3;

    # Include other h5bp conf files
    include /etc/nginx/h5bpconf/x-ua-compatible.conf;
    include /etc/nginx/h5bpconf/protect-system-files.conf;
    #include /etc/nginx/h5bpconf/cross-domain-ajax.conf;
    include /etc/nginx/h5bpconf/no-transform.conf;

    location / {

    ## Handle alternate domains first
    # include /var/www/testing/nginx_conf/alternate_domains.conf;

            # First attempt to serve request as file, then
            # as directory, then fall back
            try_files $uri $uri/ @fallback;

            # these h5bp configs only have an effect if try_files finds a file
            include /etc/nginx/h5bpconf/expires.conf;
            include /etc/nginx/h5bpconf/cross-domain-fonts.conf;
            # Uncomment to enable naxsi on this location
            # include /etc/nginx/naxsi.rules
    }

    location @fallback {
            proxy_pass http://media.foo.com;
            #return 404;
    }

    # if you don't like seeing all the errors for missing favicon.ico in root
    location = /favicon.ico { access_log off; log_not_found off; }

    # if you don't like seeing errors for a missing robots.txt in root
    location = /robots.txt { access_log off; log_not_found off; }

    # this will prevent files like .htaccess .htpassword .secret etc from being served
    # You can remove the log directives if you wish to
    # log any attempts at a client trying to access a hidden file
    #location ~ /\. { deny all; access_log off; log_not_found off; }

    #location /doc/ {
    #        alias /usr/share/doc/;
    #        autoindex on;
    #        allow 127.0.0.1;
    #        deny all;
    #}

    # Only for nginx-naxsi : process denied requests
    #location /RequestDenied {
            # For example, return an error code
            #return 418;
    #}

    #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 /usr/share/nginx/www;
    #}

}

测试服务器是 testing.media.foo.com 而生产服务器是 media.foo.com 如果在 testing.media.foo.com 上找不到图像,我希望它从 media.foo.com 加载,而不是总是将图像从生产复制到测试中。

编辑:这是 nginx -V 的输出 --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --lock-path=/var/lock/nginx.lock --pid-path=/var/run/nginx.pid --with-debug --with-http_addition_module --with-http_dav_module --with-http_flv_module --带有-http_geoip_module --带有-http_gzip_static_module --带有-http_image_filter_module --带有-http_mp4_module --带有-http_perl_module --带有-http_random_index_module --带有-http_realip_module --带有-http_secure_link_module --带有-http_stub_status_module --带有-http_ssl_module --带有-http_sub_module --带有-http_xslt_module --带有-ipv6 --带有-sha1=/usr/include/openssl --带有-md5=/usr/include/openssl --带有-mail --带有-mail_ssl_module --add-module=/build/buildd/nginx-1.1.19/debian/modules/nginx-auth-pam --add-module=/build/buildd/nginx-1.1.19/debian/modules/chunkin-nginx-module --add-module=/build/buildd/nginx-1.1.19/debian/modules/headers-more-nginx-module --add-module=/build/buildd/nginx-1.1.19/debian/modules/nginx-development-kit --add-module=/build/buildd/nginx-1.1.19/debian/modules/nginx-echo --add-module=/build/buildd/nginx-1.1.19/debian/modules/nginx-http-push --add-module=/build/buildd/nginx-1.1.19/debian/modules/nginx-lua --add-module=/build/buildd/nginx-1.1.19/debian/modules/nginx-upload-module --add-module=/build/buildd/nginx-1.1.19/debian/modules/nginx-upload-progress --add-module=/build/buildd/nginx-1.1.19/debian/modules/nginx-upstream-fair --add-module=/build/buildd/nginx-1.1.19/debian/modules/nginx-dav-ext-module

相关内容