title: TCP proxy to postgres database as an upstream server in nginx
body: <p>Question: Is it possible to set Nginx as a reverse proxy for a database?
  These are the flags I have at the moment and I believed that having the <code>--with-stream</code> module was sufficient to use TCP streams to the database. Is this a PLUS feature?</p>
  <p>Nginx configuration options:</p>
  <blockquote>
  <p>--prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=%{_libdir}/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-threads --with-stream --with-stream_ssl_module --with-http_slice_module --with-mail --with-mail_ssl_module --with-file-aio --with-http_v2_module --with-cc-opt='-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-z,relro -Wl,--as-needed' --with-ipv6</p>
  </blockquote>
  <p>Nginx config</p>
  <pre><code>stream {
  
      include conf.d/streams/*.conf;
  }
  </code></pre>
  <p>contents of <code>conf.d/streams/upstream.conf</code></p>
  <pre><code>upstream database_server {
      least_conn;
      keepalive 512;
      server 192.168.99.103:32778 max_fails=5 fail_timeout=30s weight=1;
  
  }
  </code></pre>
  <p>Error message from Nginx</p>
  <blockquote>
  <p>2016/02/22 03:54:13 [emerg] 242#242: invalid host in upstream &quot;http://database_server&quot; in /etc/nginx/conf.d/streams/database_server.conf:9</p>
  </blockquote>