I would like to have an api like this:


that streams a response from http://example.com/foo.pdf. Note in this case http://example.com/foo.pdf is just an example, this could be any pdf url.

So in nginx.conf sudo code:

    location ~* ^/(?<urlpath>.*)$ {
      proxy_pass $urlpath;

Is this possible with nginx + some other plugin? Looking for some pointers on implementing this.

New contributor
nginxdreams is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • Are you asking how to send the full request URI, including the Host, to the upstream? – xofer Sep 11 at 19:22

It is covered here. Essentially you will just use proxy_pass, e.g.:

location ~* ^/(?<pschema>https?)/(?<phost>[\w.]+)(?<puri>/.*) {
    set $adr $pschema://$phost;
    rewrite .* $puri break;

    proxy_pass $adr;

    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $phost;
    proxy_set_header X-NginX-Proxy true;
    proxy_redirect off;
    proxy_connect_timeout 1;
    proxy_intercept_errors on;
    expires 30;

Your Answer

nginxdreams is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.