check nginx.pm version
diff --git a/docs/GNUmakefile b/docs/GNUmakefile
index 7f2d45a..1198e42 100644
--- a/docs/GNUmakefile
+++ b/docs/GNUmakefile
@@ -1,6 +1,6 @@
 
-VER=	$(shell grep NGINX_VER src/core/nginx.h				\
-		| sed -e 's%^.*\"nginx/\(.*\)\"%\1%')
+VER=	$(shell grep 'define NGINX_VERSION' src/core/nginx.h		\
+		| sed -e 's/^.*\"\(.*\)\"/\1/')
 NGINX=	nginx-$(VER)
 TEMP=	tmp
 CP=	$(HOME)/java
diff --git a/misc/GNUmakefile b/misc/GNUmakefile
index f911c83..158d7a1 100644
--- a/misc/GNUmakefile
+++ b/misc/GNUmakefile
@@ -1,6 +1,6 @@
 
-VER=	$(shell grep NGINX_VER src/core/nginx.h				\
-		| sed -e 's%^.*\"nginx/\(.*\)\"%\1%')
+VER=	$(shell grep 'define NGINX_VERSION' src/core/nginx.h		\
+		| sed -e 's/^.*\"\(.*\)\"/\1/')
 NGINX=	nginx-$(VER)
 TEMP=	tmp
 
diff --git a/src/core/nginx.h b/src/core/nginx.h
index 20003fd..f761a79 100644
--- a/src/core/nginx.h
+++ b/src/core/nginx.h
@@ -8,7 +8,8 @@
 #define _NGINX_H_INCLUDED_
 
 
-#define NGINX_VER          "nginx/0.4.9"
+#define NGINX_VERSION      "0.4.9"
+#define NGINX_VER          "nginx/" NGINX_VERSION
 
 #define NGINX_VAR          "NGINX"
 #define NGX_OLDPID_EXT     ".oldbin"
diff --git a/src/http/modules/perl/nginx.pm b/src/http/modules/perl/nginx.pm
index 309eaa5..2ab9820 100644
--- a/src/http/modules/perl/nginx.pm
+++ b/src/http/modules/perl/nginx.pm
@@ -17,7 +17,7 @@
     HTTP_SERVER_ERROR
 );
 
-our $VERSION = '0.4.0';
+our $VERSION = '0.4.9';
 
 require XSLoader;
 XSLoader::load('nginx', $VERSION);
diff --git a/src/http/modules/perl/ngx_http_perl_module.c b/src/http/modules/perl/ngx_http_perl_module.c
index e59ece4..4fd1948 100644
--- a/src/http/modules/perl/ngx_http_perl_module.c
+++ b/src/http/modules/perl/ngx_http_perl_module.c
@@ -565,7 +565,9 @@
     ngx_log_t *log)
 {
     int                n;
-    char              *embedding[6];
+    STRLEN             len;
+    SV                *sv;
+    char              *ver, *embedding[6];
     PerlInterpreter   *perl;
 
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0, "create perl interpreter");
@@ -634,6 +636,16 @@
         goto fail;
     }
 
+    sv = get_sv("nginx::VERSION", FALSE);
+    ver = SvPV(sv, len);
+
+    if (ngx_strcmp(ver, NGINX_VERSION) != 0) {
+        ngx_log_error(NGX_LOG_ALERT, log, 0,
+                      "version " NGINX_VERSION " of nginx.pm is required, "
+                      "but %s was found", ver);
+        goto fail;
+    }
+
     if (ngx_http_perl_run_requires(aTHX_ &pmcf->requires, log) != NGX_OK) {
         goto fail;
     }
diff --git a/src/http/modules/perl/ngx_http_perl_module.h b/src/http/modules/perl/ngx_http_perl_module.h
index 66d15da..5a3d508 100644
--- a/src/http/modules/perl/ngx_http_perl_module.h
+++ b/src/http/modules/perl/ngx_http_perl_module.h
@@ -11,6 +11,7 @@
 #include <ngx_config.h>
 #include <ngx_core.h>
 #include <ngx_http.h>
+#include <nginx.h>
 
 #include <EXTERN.h>
 #include <perl.h>