@@ -0,0 +1,681 @@
+diff -rupN nginx-1.5.8/auto/modules nginx-1.5.8-proxy/auto/modules
+--- nginx-1.5.8/auto/modules 2013-12-17 14:46:27.000000000 +0100
++++ nginx-1.5.8-proxy/auto/modules 2014-01-18 00:52:25.398636700 +0100
+@@ -303,6 +303,10 @@ if [ $HTTP_SSL = YES ]; then
+ HTTP_SRCS="$HTTP_SRCS $HTTP_SSL_SRCS"
+ fi
+
++if [ $PROXY_PROTOCOL = YES ]; then
++ have=NGX_PROXY_PROTOCOL . auto/have
++fi
++
+ if [ $HTTP_PROXY = YES ]; then
+ have=NGX_HTTP_X_FORWARDED_FOR . auto/have
+ #USE_MD5=YES
+diff -rupN nginx-1.5.8/auto/options nginx-1.5.8-proxy/auto/options
+--- nginx-1.5.8/auto/options 2013-12-17 14:46:27.000000000 +0100
++++ nginx-1.5.8-proxy/auto/options 2014-01-18 00:52:25.400636800 +0100
+@@ -47,6 +47,8 @@ USE_THREADS=NO
+ NGX_FILE_AIO=NO
+ NGX_IPV6=NO
+
++PROXY_PROTOCOL=NO
++
+ HTTP=YES
+
+ NGX_HTTP_LOG_PATH=
+@@ -193,6 +195,8 @@ do
+ --with-file-aio) NGX_FILE_AIO=YES ;;
+ --with-ipv6) NGX_IPV6=YES ;;
+
++ --with-proxy-protocol) PROXY_PROTOCOL=YES ;;
++
+ --without-http) HTTP=NO ;;
+ --without-http-cache) HTTP_CACHE=NO ;;
+
+@@ -352,6 +356,8 @@ cat << END
+ --with-file-aio enable file AIO support
+ --with-ipv6 enable IPv6 support
+
++ --with-proxy-protocol enable proxy protocol support
++
+ --with-http_ssl_module enable ngx_http_ssl_module
+ --with-http_spdy_module enable ngx_http_spdy_module
+ --with-http_realip_module enable ngx_http_realip_module
+diff -rupN nginx-1.5.8/auto/sources nginx-1.5.8-proxy/auto/sources
+--- nginx-1.5.8/auto/sources 2013-12-17 14:46:27.000000000 +0100
++++ nginx-1.5.8-proxy/auto/sources 2014-01-18 00:52:25.404637100 +0100
+@@ -36,7 +36,8 @@ CORE_DEPS="src/core/nginx.h \
+ src/core/ngx_conf_file.h \
+ src/core/ngx_resolver.h \
+ src/core/ngx_open_file_cache.h \
+- src/core/ngx_crypt.h"
++ src/core/ngx_crypt.h \
++ src/core/ngx_proxy_protocol.h"
+
+
+ CORE_SRCS="src/core/nginx.c \
+@@ -67,7 +68,8 @@ CORE_SRCS="src/core/nginx.c \
+ src/core/ngx_conf_file.c \
+ src/core/ngx_resolver.c \
+ src/core/ngx_open_file_cache.c \
+- src/core/ngx_crypt.c"
++ src/core/ngx_crypt.c \
++ src/core/ngx_proxy_protocol.c"
+
+
+ REGEX_MODULE=ngx_regex_module
+diff -rupN nginx-1.5.8/src/core/ngx_connection.h nginx-1.5.8-proxy/src/core/ngx_connection.h
+--- nginx-1.5.8/src/core/ngx_connection.h 2013-12-17 14:46:27.000000000 +0100
++++ nginx-1.5.8-proxy/src/core/ngx_connection.h 2014-01-18 00:52:25.407637200 +0100
+@@ -63,6 +63,10 @@ struct ngx_listening_s {
+ unsigned shared:1; /* shared between threads or processes */
+ unsigned addr_ntop:1;
+
++#if (NGX_PROXY_PROTOCOL)
++ unsigned accept_proxy_protocol:2; /* proxy_protocol flag */
++#endif
++
+ #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
+ unsigned ipv6only:1;
+ #endif
+@@ -153,6 +157,10 @@ struct ngx_connection_s {
+
+ ngx_uint_t requests;
+
++#if (NGX_PROXY_PROTOCOL)
++ ngx_uint_t proxy_protocol;
++#endif
++
+ unsigned buffered:8;
+
+ unsigned log_error:3; /* ngx_connection_log_error_e */
+diff -rupN nginx-1.5.8/src/core/ngx_core.h nginx-1.5.8-proxy/src/core/ngx_core.h
+--- nginx-1.5.8/src/core/ngx_core.h 2013-12-17 14:46:27.000000000 +0100
++++ nginx-1.5.8-proxy/src/core/ngx_core.h 2014-01-18 00:52:25.412637500 +0100
+@@ -21,6 +21,9 @@ typedef struct ngx_file_s ngx_fil
+ typedef struct ngx_event_s ngx_event_t;
+ typedef struct ngx_event_aio_s ngx_event_aio_t;
+ typedef struct ngx_connection_s ngx_connection_t;
++#if (NGX_PROXY_PROTOCOL)
++typedef struct ngx_proxy_protocol_s ngx_proxy_protocol_t;
++#endif
+
+ typedef void (*ngx_event_handler_pt)(ngx_event_t *ev);
+ typedef void (*ngx_connection_handler_pt)(ngx_connection_t *c);
+@@ -77,6 +80,9 @@ typedef void (*ngx_connection_handler_pt
+ #include <ngx_open_file_cache.h>
+ #include <ngx_os.h>
+ #include <ngx_connection.h>
++#if (NGX_PROXY_PROTOCOL)
++#include <ngx_proxy_protocol.h>
++#endif
+
+
+ #define LF (u_char) 10
+diff -rupN nginx-1.5.8/src/http/modules/ngx_http_proxy_module.c nginx-1.5.8-proxy/src/http/modules/ngx_http_proxy_module.c
+--- nginx-1.5.8/src/http/modules/ngx_http_proxy_module.c 2013-12-17 14:46:27.000000000 +0100
++++ nginx-1.5.8-proxy/src/http/modules/ngx_http_proxy_module.c 2014-01-18 00:52:25.422638100 +0100
+@@ -8,7 +8,9 @@
+ #include <ngx_config.h>
+ #include <ngx_core.h>
+ #include <ngx_http.h>
+-
++#if (NGX_PROXY_PROTOCOL)
++#include <ngx_proxy_protocol.h>
++#endif
+
+ typedef struct ngx_http_proxy_rewrite_s ngx_http_proxy_rewrite_t;
+
+@@ -386,6 +388,17 @@ static ngx_command_t ngx_http_proxy_com
+ offsetof(ngx_http_proxy_loc_conf_t, upstream.busy_buffers_size_conf),
+ NULL },
+
++#if (NGX_PROXY_PROTOCOL)
++
++ { ngx_string("send_proxy_protocol"),
++ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
++ ngx_conf_set_flag_slot,
++ NGX_HTTP_LOC_CONF_OFFSET,
++ offsetof(ngx_http_proxy_loc_conf_t, upstream.send_proxy_protocol),
++ NULL },
++
++#endif
++
+ #if (NGX_HTTP_CACHE)
+
+ { ngx_string("proxy_cache"),
+@@ -2441,6 +2454,11 @@ ngx_http_proxy_create_loc_conf(ngx_conf_
+ conf->upstream.pass_headers = NGX_CONF_UNSET_PTR;
+
+ conf->upstream.intercept_errors = NGX_CONF_UNSET;
++
++#if (NGX_PROXY_PROTOCOL)
++ conf->upstream.send_proxy_protocol = NGX_CONF_UNSET;
++#endif
++
+ #if (NGX_HTTP_SSL)
+ conf->upstream.ssl_session_reuse = NGX_CONF_UNSET;
+ #endif
+@@ -2713,6 +2731,11 @@ ngx_http_proxy_merge_loc_conf(ngx_conf_t
+ ngx_conf_merge_value(conf->upstream.intercept_errors,
+ prev->upstream.intercept_errors, 0);
+
++#if (NGX_PROXY_PROTOCOL)
++ ngx_conf_merge_value(conf->upstream.send_proxy_protocol,
++ prev->upstream.send_proxy_protocol, 0);
++#endif
++
+ #if (NGX_HTTP_SSL)
+ ngx_conf_merge_value(conf->upstream.ssl_session_reuse,
+ prev->upstream.ssl_session_reuse, 1);
+diff -rupN nginx-1.5.8/src/http/ngx_http.c nginx-1.5.8-proxy/src/http/ngx_http.c
+--- nginx-1.5.8/src/http/ngx_http.c 2013-12-17 14:46:27.000000000 +0100
++++ nginx-1.5.8-proxy/src/http/ngx_http.c 2014-01-18 00:52:25.426638300 +0100
+@@ -1231,6 +1231,9 @@ ngx_http_add_addresses(ngx_conf_t *cf, n
+ #if (NGX_HTTP_SPDY)
+ ngx_uint_t spdy;
+ #endif
++#if (NGX_PROXY_PROTOCOL)
++ ngx_uint_t accept_proxy_protocol;
++#endif
+
+ /*
+ * we cannot compare whole sockaddr struct's as kernel
+@@ -1286,6 +1289,10 @@ ngx_http_add_addresses(ngx_conf_t *cf, n
+ #if (NGX_HTTP_SPDY)
+ spdy = lsopt->spdy || addr[i].opt.spdy;
+ #endif
++#if (NGX_PROXY_PROTOCOL)
++ accept_proxy_protocol = lsopt->accept_proxy_protocol
++ || addr[i].opt.accept_proxy_protocol;
++#endif
+
+ if (lsopt->set) {
+
+@@ -1319,6 +1326,9 @@ ngx_http_add_addresses(ngx_conf_t *cf, n
+ #if (NGX_HTTP_SPDY)
+ addr[i].opt.spdy = spdy;
+ #endif
|