Opened 8 years ago

Closed 8 years ago

Last modified 6 years ago

#1207 closed defect (invalid)

Distinguish between 301 and 302 redirects when proxy_redirect off

Reported by: stackoverflow.com/users/4514467/hugmanrique Owned by:
Priority: minor Milestone: 1.11
Component: nginx-core Version: 1.9.x
Keywords: proxy, redirections Cc:
uname -a: Linux hugmanrique 4.4.0-38-generic #57-Ubuntu SMP Tue Sep 6 15:42:33 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.10.0 (Ubuntu)
built with OpenSSL 1.0.2g 1 Mar 2016
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wforat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now' --prefix=/usr/share/ngix --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log -error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-ath=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy--http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginxuwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-htp_stub_status_module --with-http_realip_module --with-http_auth_request_module -with-http_addition_module --with-http_dav_module --with-http_geoip_module --wih-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_moule --with-http_v2_module --with-http_sub_module --with-http_xslt_module --withstream --with-stream_ssl_module --with-mail --with-mail_ssl_module --with-threas

Description

I'm creating an app that proxies it's content to imgur. When an image doesn't exist, it returns a 302 redirection to the 404 page which then throws a 404 (not catched by proxy_intercept_errors on; because a 302 is considered the first error by nginx). When people are using a phone, imgur throws a 301 redirection to m.imgur.com/route. Both examples are cached by my error_page when I would only want to catch the 302 redirection as an error. Here's my config:

server {

listen 443 ssl http2;
listen [::]:443 ssl http2;

server_name domain.tld;

ssl_certificate /path/a.pem;
ssl_certificate_key /path/b.pem;

root /path/web/;
index index.html;

error_page 301 302 307 501 502 503 400 404 = /notFound.html;

location ~ \.(png|gif|jpg|gifv) {

proxy_pass https://i.imgur.com;
proxy_redirect off;
proxy_intercept_errors on;

}

}

A proxy_redirect_type option would be neat for these cases. Even if I remove the 301 from the error_page, nginx still catches it and serves a default error page.

Change History (6)

comment:1 by Maxim Dounin, 8 years ago

The 302 and 301 codes aren't special, nginx handles them much like any other status codes. The proxy_redirect directive configures processing of the Location and Refresh response headers, and there will be no processing as long as this directive is switched off.

Do you have proxy_cache also enabled in your configuration?

It looks like yes, and your problem is that you have proxy_intercept_errors switched on, error_page configured for both 301 and 302, and caching enabled. This means that nginx will intercept these errors, and will do special caching for them: it will store only the code itself, so any response from the cache will be handled as an intercepted error, regardless of the current settings. That is, to obtain the result you want you need to do two things:

  • Remove 301 from the error_page, much like you've already tried to do.
  • Flush the cache or wait for it to expire. Intercepted errors are cached only in memory, so a restart (or binary upgrade) whould do the trick.

comment:2 by stackoverflow.com/users/4514467/hugmanrique, 8 years ago

A restart seems to have fixed the issue. Thanks for your reply!

comment:3 by Maxim Dounin, 8 years ago

Resolution: invalid
Status: newclosed

comment:4 by tir94@…, 8 years ago

I'll some problem, fixed.
https://logoreg.com/favicon.png
https://vehiclepad.com/favicon.png

comment:5 by melihusa2016@…, 8 years ago

I didn't fix my problem.Please help me.

Restart didn't solve my problem.

Still,I'm trying.

https://img.clippp.com/dfc90a349686cffa1985f68c64b64961_zlatan-ibrahimovic-tattooed-names-of-50-starving-people-on-his-zlatan-ibrahimovic-tattoo_306-468.jpeg

comment:6 by Maxim Dounin, 8 years ago

If you need help with configuring nginx, consider asking for help in mailing lists.

Note: See TracTickets for help on using tickets.