[mapserver-commits] r12967 - trunk/mapserver/mapcache/nginx

svn at osgeo.org svn at osgeo.org
Wed Jan 4 13:06:45 EST 2012


Author: tbonfort
Date: 2012-01-04 10:06:45 -0800 (Wed, 04 Jan 2012)
New Revision: 12967

Added:
   trunk/mapserver/mapcache/nginx/README
   trunk/mapserver/mapcache/nginx/nginx.conf
Modified:
   trunk/mapserver/mapcache/nginx/ngx_http_mapcache_module.c
Log:
working nginx mapcache module


Added: trunk/mapserver/mapcache/nginx/README
===================================================================
--- trunk/mapserver/mapcache/nginx/README	                        (rev 0)
+++ trunk/mapserver/mapcache/nginx/README	2012-01-04 18:06:45 UTC (rev 12967)
@@ -0,0 +1,16 @@
+minimal install instructions:
+
+- configure nginx with
+
+./configure --add-module=/path/to/mapcache/nginx
+
+the supplied nginx.conf contains an example configuration to load mapcache.
+the relevant part is:
+
+        location ~ ^/mapcache(?<path_info>/.*|$) {
+           set $url_prefix "/mapcache";
+           mapcache /home/tbonfort/dev/mapserver-trunk/mapcache/mapcache.xml;
+        }
+
+the <path_info> and $url_prefix are important and are used by mapcache
+to parse the incoming requests.

Added: trunk/mapserver/mapcache/nginx/nginx.conf
===================================================================
--- trunk/mapserver/mapcache/nginx/nginx.conf	                        (rev 0)
+++ trunk/mapserver/mapcache/nginx/nginx.conf	2012-01-04 18:06:45 UTC (rev 12967)
@@ -0,0 +1,124 @@
+
+#user  nobody;
+worker_processes     4;
+#master_process  on;
+
+#error_log  logs/error.log;
+#error_log  logs/error.log  notice;
+#error_log  logs/error.log  info;
+
+#pid        logs/nginx.pid;
+
+
+events {
+    worker_connections  1024;
+}
+
+
+http {
+    include       mime.types;
+    default_type  application/octet-stream;
+
+    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
+    #                  '$status $body_bytes_sent "$http_referer" '
+    #                  '"$http_user_agent" "$http_x_forwarded_for"';
+
+    #access_log  logs/access.log  main;
+
+    sendfile        on;
+    #tcp_nopush     on;
+
+    #keepalive_timeout  0;
+    keepalive_timeout  5;
+
+    #gzip  on;
+
+    server {
+        listen       8083;
+        server_name  localhost;
+
+        #charset koi8-r;
+
+        #access_log  logs/host.access.log  main;
+
+        location / {
+            root   html;
+            index  index.html index.htm;
+        }
+
+        #error_page  404              /404.html;
+
+        # redirect server error pages to the static page /50x.html
+        #
+        error_page   500 502 503 504  /50x.html;
+        location = /50x.html {
+            root   html;
+        }
+
+        location ~ ^/mapcache(?<path_info>/.*|$) {
+           set $url_prefix "/mapcache";
+           mapcache /home/tbonfort/dev/mapserver-trunk/mapcache/mapcache.xml;
+        }
+
+        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
+        #
+        #location ~ \.php$ {
+        #    proxy_pass   http://127.0.0.1;
+        #}
+
+        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
+        #
+        #location ~ \.php$ {
+        #    root           html;
+        #    fastcgi_pass   127.0.0.1:9000;
+        #    fastcgi_index  index.php;
+        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
+        #    include        fastcgi_params;
+        #}
+
+        # deny access to .htaccess files, if Apache's document root
+        # concurs with nginx's one
+        #
+        #location ~ /\.ht {
+        #    deny  all;
+        #}
+    }
+
+
+    # another virtual host using mix of IP-, name-, and port-based configuration
+    #
+    #server {
+    #    listen       8000;
+    #    listen       somename:8080;
+    #    server_name  somename  alias  another.alias;
+
+    #    location / {
+    #        root   html;
+    #        index  index.html index.htm;
+    #    }
+    #}
+
+
+    # HTTPS server
+    #
+    #server {
+    #    listen       443;
+    #    server_name  localhost;
+
+    #    ssl                  on;
+    #    ssl_certificate      cert.pem;
+    #    ssl_certificate_key  cert.key;
+
+    #    ssl_session_timeout  5m;
+
+    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
+    #    ssl_ciphers  HIGH:!aNULL:!MD5;
+    #    ssl_prefer_server_ciphers   on;
+
+    #    location / {
+    #        root   html;
+    #        index  index.html index.htm;
+    #    }
+    #}
+
+}

Modified: trunk/mapserver/mapcache/nginx/ngx_http_mapcache_module.c
===================================================================
--- trunk/mapserver/mapcache/nginx/ngx_http_mapcache_module.c	2012-01-04 17:25:23 UTC (rev 12966)
+++ trunk/mapserver/mapcache/nginx/ngx_http_mapcache_module.c	2012-01-04 18:06:45 UTC (rev 12967)
@@ -179,6 +179,10 @@
     NGX_MODULE_V1_PADDING
 };
 
+static ngx_str_t  pathinfo_str = ngx_string("path_info");
+static ngx_int_t pathinfo_index;
+static ngx_str_t  urlprefix_str = ngx_string("url_prefix");
+static ngx_int_t urlprefix_index;
 
 static ngx_int_t
 ngx_http_mapcache_handler(ngx_http_request_t *r)
@@ -192,9 +196,12 @@
     mapcache_request *request = NULL;
     mapcache_http_response *http_response;
 
-    char* pathInfo = "/";
+   ngx_http_variable_value_t      *pathinfovv = ngx_http_get_indexed_variable(r, pathinfo_index);
+
+    char* pathInfo = apr_pstrndup(ctx->pool, (char*)pathinfovv->data, pathinfovv->len);
       char *sparams = apr_pstrndup(ctx->pool, (char*)r->args.data, r->args.len);
       apr_table_t *params = mapcache_http_parse_param_string(ctx, sparams);
+
       mapcache_service_dispatch_request(ctx,&request,pathInfo,params,ctx->config);
       if(GC_HAS_ERROR(ctx) || !request) {
          ngx_http_mapcache_write_response(ctx,r, mapcache_core_respond_to_error(ctx));
@@ -204,26 +211,13 @@
       http_response = NULL;
       if(request->type == MAPCACHE_REQUEST_GET_CAPABILITIES) {
          mapcache_request_get_capabilities *req = (mapcache_request_get_capabilities*)request;
-         char *host = getenv("SERVER_NAME");
-         char *port = getenv("SERVER_PORT");
-         char *fullhost;
-         char *url;
-         if(getenv("HTTPS")) {
-            if(!port || !strcmp(port,"443")) {
-               fullhost = apr_psprintf(ctx->pool,"https://%s",host);
-            } else {
-               fullhost = apr_psprintf(ctx->pool,"https://%s:%s",host,port);
-            }
-         } else {
-            if(!port || !strcmp(port,"80")) {
-               fullhost = apr_psprintf(ctx->pool,"http://%s",host);
-            } else {
-               fullhost = apr_psprintf(ctx->pool,"http://%s:%s",host,port);
-            }
-         }
-         url = apr_psprintf(ctx->pool,"%s%s/",
-               fullhost,
-               getenv("SCRIPT_NAME")
+         ngx_http_variable_value_t      *urlprefixvv = ngx_http_get_indexed_variable(r, urlprefix_index);
+         char *url = apr_pstrcat(ctx->pool,
+               "http://",
+               apr_pstrndup(ctx->pool, (char*)r->headers_in.host->value.data, r->headers_in.host->value.len),
+               apr_pstrndup(ctx->pool, (char*)urlprefixvv->data, urlprefixvv->len),
+               "/",
+               NULL
                );
          http_response = mapcache_core_get_capabilities(ctx,request->service,req,url,pathInfo,ctx->config);
       } else if( request->type == MAPCACHE_REQUEST_GET_TILE) {
@@ -289,5 +283,14 @@
     clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
     clcf->handler = ngx_http_mapcache_handler;
 
+   pathinfo_index = ngx_http_get_variable_index(cf, &pathinfo_str);
+   if (pathinfo_index == NGX_ERROR) {
+		return NGX_CONF_ERROR;
+	}
+   urlprefix_index = ngx_http_get_variable_index(cf, &urlprefix_str);
+   if (urlprefix_index == NGX_ERROR) {
+		return NGX_CONF_ERROR;
+	}
+
     return NGX_CONF_OK;
 }



More information about the mapserver-commits mailing list