MapServer / mapcache

MapCache source code directory. Please submit pull requests to the 'main' branch.
https://mapserver.org/mapcache
Other
137 stars 96 forks source link

Error images with Fastcgi instances of Mapcache in NGINX and Spawn-fcgi #89

Open samtux opened 10 years ago

samtux commented 10 years ago

I have done the configuration of the FastCGI instance of Mapcache in Nginx Server, but accessing from a remote IP the tiles appear in pink in OpenLayers demo MapCache, because the path of the images are on "localhost".

The Spawn cofiguration is:

# cat /etc/init.d/spawn-fcgi

#! /bin/sh

set -e

export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"

case "$1" in
  start)

        echo "Arrancando spawn-mapcache..."
        # Nota: variar -C XXX (número de procesos Mapcahe concurrentes) 
        # según sea necesario para soportar carga de la web.
        /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 20 \
                            -u www-data -g www-data \
                            -f /usr/local/bin/mapcache.fcgi \
                            -P /var/run/fastcgi-mapcache.pid
                            ;;
  stop)
        echo "Parando spawn-mapcache..."
        killall mapcache.fcgi
        sleep 5
        killall -9 mapcache.fcgi
        ;;

  restart)
  $0 stop
        $0 start
        ;;

  *)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
esac

exit 0

The Fastcgi instances of mapcache in Nginx configuration:

location ~ ^/mapcache(?<path_info>/.*|$) {
   set $url_prefix "/mapcache";
   set $mapcache "/srv/mapcache/mapcache.xml";
   error_page 404 = @fastcgi_mapcache;
}

location @fastcgi_mapcache {
   fastcgi_pass   127.0.0.1:9000;
   fastcgi_param  QUERY_STRING     $query_string;
   fastcgi_param  REQUEST_METHOD   $request_method;
   fastcgi_param  CONTENT_TYPE     $content_type;
   fastcgi_param  CONTENT_LENGTH   $content_length;
   fastcgi_param  PATH_INFO        $path_info;
   fastcgi_param  SERVER_NAME      $server_name;
   fastcgi_param  SERVER_PORT      $server_port;
   fastcgi_param  SCRIPT_NAME      "/mapcache";
}

How I can fix images paths, to take the user's IP?

pedros007 commented 7 years ago

My "fix" is to run Nginx listening on port 80.

When Nginx is listening on port 80 and I visit a service listed on http://localhost/mapcache/demo, tiles are requested correctly from localhost. When Nginx is listening on another port (e.g. 8080), then visiting a service via http://localhost:8080/mapcache/demo will fetch tiles incorrectly via http://localhost on port 80, resulting in pink tiles.