Index: szn-nginx/auto/cc/conf
===================================================================
--- szn-nginx.orig/auto/cc/conf
+++ szn-nginx/auto/cc/conf
@@ -142,6 +142,7 @@ else
 fi
 
 CFLAGS="$CFLAGS $NGX_CC_OPT"
+CXXFLAGS="$CXXFLAGS $NGX_CXX_OPT"
 NGX_TEST_LD_OPT="$NGX_LD_OPT"
 
 if [ "$NGX_PLATFORM" != win32 ]; then
Index: szn-nginx/auto/make
===================================================================
--- szn-nginx.orig/auto/make
+++ szn-nginx/auto/make
@@ -21,7 +21,9 @@ ngx_use_pch=`echo $NGX_USE_PCH | sed -e
 cat << END                                                     > $NGX_MAKEFILE
 
 CC =	$CC
+CXX = $CXX
 CFLAGS = $CFLAGS
+CXXFLAGS = $CXXFLAGS
 CPP =	$CPP
 LINK =	$LINK
 
@@ -408,10 +410,15 @@ fi
 
 if test -n "$NGX_ADDON_SRCS"; then
 
-    ngx_cc="\$(CC) $ngx_compile_opt \$(CFLAGS) $ngx_use_pch \$(ALL_INCS)"
+    # Use CC and CFLAGS if CXX is not set
+    if [ -z "$CXX" ]; then
+       CXX="$CC"
+       CXXFLAGS="$CFLAGS"
+    fi;
 
     for ngx_src in $NGX_ADDON_SRCS
     do
+        ngx_src_is_cpp=`echo $ngx_src | grep -E "\.(ii|cc|cp|cxx|(?i)cpp(?-i)|c\+\+|C)$" | wc -l`
         ngx_obj="addon/`basename \`dirname $ngx_src\``"
 
         ngx_obj=`echo $ngx_obj/\`basename $ngx_src\` \
@@ -425,6 +432,13 @@ if test -n "$NGX_ADDON_SRCS"; then
 
         ngx_src=`echo $ngx_src | sed -e "s/\//$ngx_regex_dirsep/g"`
 
+        # Use CXX compiler and flags for C++ modules
+        if [ "$ngx_src_is_cpp" -eq '1' ]; then
+            ngx_cc="\$(CXX) $ngx_compile_opt \$(CXXFLAGS) $ngx_use_pch \$(ALL_INCS)"
+        else
+            ngx_cc="\$(CC) $ngx_compile_opt \$(CFLAGS) $ngx_use_pch \$(ALL_INCS)"
+        fi;
+
         cat << END                                            >> $NGX_MAKEFILE
 
 $ngx_obj:	\$(ADDON_DEPS)$ngx_cont$ngx_src
Index: szn-nginx/auto/options
===================================================================
--- szn-nginx.orig/auto/options
+++ szn-nginx/auto/options
@@ -23,6 +23,7 @@ NGX_OBJS=objs
 
 NGX_DEBUG=NO
 NGX_CC_OPT=
+NGX_CXX_OPT=
 NGX_LD_OPT=
 CPU=NO
 
@@ -343,8 +344,10 @@ use the \"--with-mail_ssl_module\" optio
         --with-compat)                   NGX_COMPAT=YES             ;;
 
         --with-cc=*)                     CC="$value"                ;;
+        --with-cxx=*)                    CXX="$value"               ;;
         --with-cpp=*)                    CPP="$value"               ;;
         --with-cc-opt=*)                 NGX_CC_OPT="$value"        ;;
+        --with-cxx-opt=*)                NGX_CXX_OPT="$value"       ;;
         --with-ld-opt=*)                 NGX_LD_OPT="$value"        ;;
         --with-cpu-opt=*)                CPU="$value"               ;;
         --with-debug)                    NGX_DEBUG=YES              ;;
@@ -557,8 +560,10 @@ cat << END
   --with-compat                      dynamic modules compatibility
 
   --with-cc=PATH                     set C compiler pathname
+  --with-cxx=PATH                    set C++ compiler pathname
   --with-cpp=PATH                    set C preprocessor pathname
   --with-cc-opt=OPTIONS              set additional C compiler options
+  --with-cxx-opt=OPTIONS             set additional C++ compiler options
   --with-ld-opt=OPTIONS              set additional linker options
   --with-cpu-opt=CPU                 build for the specified CPU, valid values:
                                      pentium, pentiumpro, pentium3, pentium4,
