Nginx reverse proxy

From wikinotes

A reverse proxy is where you have one server redirect to another
(possibly handling SSL in place of the second).

HTTP Proxy

For most consistent results, it is best to have roughly symmetrical routes (domain.com/a -> example.com/a)
on both sides of the redirect. You may possibly be able to get away with an asymmetric route
but it is fragile. See this excellent blog post (skim headers to orient yourself) http://sawers.com/blog/reverse-proxying-with-nginx/

  • symmetrical (domain.com/a -> example.com/a)
  • change port (domain.com/a -> example.com:8080/a)
  • additive (domain.com/ -> example.com/a/)
  • asymetrical (domain.com/a/ -> example.com) (domain.com/a -> example.com/b) (app/website dependent, fragile)
server {
  listen 80;

  location /docs/ {
    proxy_pass 10.0.0.1:80;
  }

  location /api/ {
    include    proxy_params;
    proxy_pass http://unix:/usr/local/www/website/serv.sock;
  }
}

There are several HTTP headers you can use to assist this proxy in behaving properly.

location / {
  proxy_set_header X-Forwarded-Host domain.com:8080;
  proxy_set_header Host domain.com:8080;
  proxy_pass 10.10.10.10:8080;
}
# TODO

SSH Proxy

load_module /usr/local/libexec/nginx/ngx_stream_module.so;

stream {
  server {
    listen 2222;
    proxy_pass 10.0.0.1:2222;
  }
}