Friday 6 September 2019

Configuring proxy.cgi in Windows using Apache and GeoServer?


I want to dispaly my layers on a server. I'am using geoserver 2.3.2 and apache 2.4


Till now i Create a proxy file in referring in this link : http://trac.osgeo.org/openlayers/browser/trunk/openlayers/examples/proxy.cgi and i Put it in cgi-bin folder. I Installed python and in the starting line of proxy.cgi i put the location of python. #!C:/Python27/python.exe -u



I found in some tutorials that i should configure the file httpd.conf and i have no idea how to configure it and where should i add this code :


" ProxyRequests Off ProxyPreserveHost On


Order deny,allow


Allow from all


ProxyPass /geoserver //localhost:8080/geoserver


ProxyPassReverse /geoserver //localhost:8080/geoserver "



Answer



Those settings look like they belong to an Apache 2.2 server. For your Apache 2.4 server you could instead try:


ProxyRequests Off
ProxyPreserveHost On



Require all granted


ProxyPass /geoserver http://127.0.0.1:8080/geoserver
ProxyPassReverse /geoserver http://127.0.0.1:8080/geoserver

Which are part of the configuration settings for Apache and added to the httpd.conf file.


You could try also using the server IP or localhost instead of 127.0.0.1 in the ProxyPass and ProxyPassReverse sections, i.e.



ProxyPass /geoserver http://localhost:8080/geoserver
ProxyPassReverse /geoserver http://localhost:8080/geoserver

or


ProxyPass /geoserver http://:8080/geoserver
ProxyPassReverse /geoserver http://:8080/geoserver

To test whether the proxying of GeoServer via Apache is working you should browse to:


http://localhost/geoserver/web/


If this page opens then the Apache web server is correctly proxying the the GeoServer server.


To help you debug any issues with the Apache configuration open a command window and try:


httpd.exe -t

If you get an error "is not recognized as an internal or external command" then the Apache httpd.exe is not in your path, you will need to change to the directory that holds the httpd.exe file before running the command. The typical location for the httpd.exe file would be in the bin sub folder such as:


* C:\Apache24\bin\

Check too that at the top of the httpd.conf file that you have uncommented (remove the #) the modules that handle proxying like:


LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so

LoadModule proxy_http_module modules/mod_proxy_http.so

Answering other questions raised in the comments:


The call to the proxy.cgi file (like below) needs to go into your JavaScript code called by the HTML page in which you create your map.


OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url=..."

The proxy.cgi file itself doesn't need to be placed in the cgi-bin folder of the Apache server; it can go anywhere but you need to enable this by editing the following directive in the Apache httpd.conf file like below (where "C:/Apache24/htdocs" is taken to be the document root).



# The Options directive is both complicated and important.
# Please see http://httpd.apache.org/docs/2.4/mod/core.html#options

#Options +FollowSymLinks +Includes

# Adding +ExecCGI allows CGI scripts to run outside of cgi-bin (and similar) script folders
Options +FollowSymLinks +Includes +ExecCGI

AllowOverride None
Require all granted


To enable the proxy.cgi file to be recognized as executable you need to uncomment the appropriate AddHandler section (within the section), like:




...
# AddHandler allows you to map certain file extensions to "handlers":
# actions unrelated to filetype. These can be either built into the server
# or added with the Action directive (see below)
#
# To use CGI scripts outside of ScriptAliased directories:
# (You will also need to add "ExecCGI" to the "Options" directive.)
#
# Enabling the below to allow python processing

AddHandler cgi-script .cgi .py
...


You need to restart Apache for the configuration changes to be enabled.


You can test that the proxy.cgi is working by browsing to it like (below), without any parameters.


http://localhost/cgi-bin/proxy.cgi

The page should redirect you to the OpenLayers home page, or whatever url you have set in the proxy.cgi section:


else:

fs = cgi.FieldStorage()
url = fs.getvalue('url', "http://www.openlayers.org")

For a working example of a Web page with OpenLayers using a proxy.cgi script see: GeoRSS Example


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...