Skip to content

Instantly share code, notes, and snippets.

@mattd
Created June 3, 2011 14:12
Show Gist options
  • Star 82 You must be signed in to star a gist
  • Fork 13 You must be signed in to fork a gist
  • Save mattd/1006398 to your computer and use it in GitHub Desktop.
Save mattd/1006398 to your computer and use it in GitHub Desktop.
nginx try_files with a proxy_pass
server {
root /var/www/example.com/static;
server_name example.com;
access_log /var/log/nginx/example.com.access.log;
error_log /var/log/nginx/example.com.error.log;
try_files /maintenance.html @proxy;
location @proxy {
proxy_pass http://127.0.0.1:10001;
include /etc/nginx/proxy.conf;
}
}
server {
root /var/www/example.com/static;
server_name example.com;
access_log /var/log/nginx/example.com.access.log;
error_log /var/log/nginx/example.com.error.log;
try_files /maintenance.html @proxy;
location @proxy {
proxy_pass http://127.0.0.1:10001;
include /etc/nginx/proxy.conf;
}
}
@ericls
Copy link

ericls commented Oct 2, 2015

brilliant

@JulienBlancher
Copy link

Thanks!

@ThomasLohner
Copy link

👍

@yannispanousis
Copy link

Thanks man! In my case both tries will be proxy_pass references... WOAH

@sinasalek
Copy link

brilliant

@ianchadwick
Copy link

Thank you!

@SJK132
Copy link

SJK132 commented Aug 12, 2018

this is gem.

@wellington1993
Copy link

Thanks!

@bartolootrit
Copy link

In the other case:

    location /static/ {
        error_page 404 = @remote_images;
        proxy_pass http://127.0.0.1:8080$request_uri;
    }

    location @remote_images {
        resolver 8.8.8.8;
        proxy_set_header Host remote.example.org;
        proxy_pass http://remote.example.org;
    }

@ivan-kleshnin
Copy link

I ended like this:

upstream your-node-name {
  server 127.0.0.1:8080;
  # server 127.0.0.1:8081;
}

server {
  try_files $uri $uri/ @nodeproxy;

  location @nodeproxy {
    proxy_pass http://your-node-name;
    ...
  }
}

@VaraPrasad62
Copy link

In case i have two locations. How to write try_file ?

@ll10020163
Copy link

brilliant

@MahmoodKamali
Copy link

What about if your server is not on the localhost? I have an issue with it. Is there any way?

@broland07
Copy link

What about if your server is not on the localhost? I have an issue with it. Is there any way?

Same problem here. I got error 500 with proxy_pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment