diff --git a/images/web/config/lighttpd.conf b/images/web/config/lighttpd.conf index 1a2088be..7b95bbf2 100644 --- a/images/web/config/lighttpd.conf +++ b/images/web/config/lighttpd.conf @@ -1,43 +1,20 @@ # default document-root -server.document-root = "/var/www/cgimap/" +server.document-root = "/openstreetmap/cgimap/" # TCP port server.port = 81 -setenv.add-response-header = ( - "Access-Control-Allow-Origin" => "*", - "Access-Control-Allow-Methods" => "GET, POST, OPTIONS", - "Access-Control-Allow-Headers" => "origin, x-requested-with, content-type" -) - -setenv.add-response-header += ( - "Access-Control-Max-Age" => "86400" # 24 hours -) - server.reject-expect-100-with-417 = "disable" # selecting modules -server.modules = ( "mod_access", "mod_rewrite", "mod_fastcgi", "mod_proxy", "mod_alias", "mod_openssl") +server.modules = ( "mod_access", "mod_rewrite", "mod_fastcgi", "mod_proxy", "mod_alias", "mod_setenv") + +# accesslog.filename = "/dev/stdout" +# server.errorlog = "/dev/stderr" # handling unknown routes server.error-handler-404 = "/dispatch.map" -# server.modules += ( "mod_setenv" ) - -# $HTTP["url"] =~ "^/api/" { -# setenv.add-response-header = ( -# "Access-Control-Allow-Origin" => "*", -# "Access-Control-Allow-Methods" => "GET, POST, OPTIONS", -# "Access-Control-Allow-Headers" => "origin, x-requested-with, content-type", -# "Access-Control-Max-Age" => "86400" -# ) -# } - -# include, relative to dirname of main config file -#include "mime.types.conf" - -# read configuration from output of a command -#include_shell "/usr/local/bin/confmimetype /etc/mime.types" mimetype.assign = ( ".html" => "text/html", ".txt" => "text/plain", @@ -45,11 +22,29 @@ mimetype.assign = ( ".png" => "image/png" ) -$HTTP["request-method"] != "OPTIONS" { - # Your existing redirect condition and rule here, for example: - $HTTP["scheme"] == "http" { - url.redirect = (".*" => "https://%0$0") - } +# Handle CORS Preflight Requests +$HTTP["request-method"] == "OPTIONS" { + setenv.add-response-header = ( + "Access-Control-Allow-Origin" => "*", + "Access-Control-Allow-Methods" => "GET, POST, PUT, DELETE, OPTIONS", + "Access-Control-Allow-Headers" => "origin, x-requested-with, content-type", + "Access-Control-Allow-Credentials" => "true", + "Access-Control-Max-Age" => "86400" + ) + server.modules += ( "mod_setenv" ) + url.access-deny = ("") +} + +server.modules += ( "mod_setenv" ) + +$HTTP["url"] =~ "^/api/0\.6/map" { + setenv.add-response-header = ( + "Access-Control-Allow-Origin" => "*", + "Access-Control-Allow-Methods" => "GET, POST, PUT, DELETE, OPTIONS", + "Access-Control-Allow-Headers" => "origin, x-requested-with, content-type", + "Access-Control-Allow-Credentials" => "true", + "Access-Control-Max-Age" => "86400" + ) } debug.log-request-handling = "enable" @@ -83,26 +78,16 @@ $HTTP["request-method"] == "PUT" { ) } -$HTTP["url"] =~ "^/(?!(dispatch\.map))" { - proxy.server = ( "" => ( ( "host" => "127.0.0.1", "port" => "80" ) ) ) -} +# $HTTP["url"] =~ "^/(?!(dispatch\.map))" { +# proxy.server = ( "" => ( ( "host" => "http://127.0.0.1", "port" => "80" ) ) ) +# } fastcgi.debug = 1 fastcgi.server = ( ".map" => - (( "socket" => "/tmp/map-fastcgi.socket", - "bin-path" => "/usr/local/bin/openstreetmap-cgimap", - "docroot" => "/", - "min-procs" => 1, - "max-procs" => 1, + (( "host" => "127.0.0.1", + "port" => 8000, "check-local" => "disable", - "bin-environment" => ( - "CGIMAP_HOST" => env.POSTGRES_HOST, - "CGIMAP_DBNAME" => env.POSTGRES_DB, - "CGIMAP_LOGFILE" => "/var/www/cgimap/log", - "CGIMAP_USERNAME" => env.POSTGRES_USER, - "CGIMAP_PASSWORD" => env.POSTGRES_PASSWORD - ) )) ) diff --git a/images/web/config/production.conf b/images/web/config/production.conf index 1f214dbf..6d7adf32 100644 --- a/images/web/config/production.conf +++ b/images/web/config/production.conf @@ -4,41 +4,33 @@ DocumentRoot /var/www/public PassengerRuby /usr/bin/ruby RewriteEngine On - RewriteCond %{HTTP:X-Forwarded-Proto} =http - RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] - - - # Handle OPTIONS requests with a 200 OK only for staging.openhistoricalmap.org - # RewriteCond %{HTTP_HOST} =tasks-staging.openhistoricalmap.org - # RewriteCond %{REQUEST_METHOD} OPTIONS - # RewriteRule ^.*$ "-" [R=200,L] + # Development mode in case domain is localhost - # # Skip redirect for other methods - # RewriteCond %{REQUEST_METHOD} !OPTIONS - # RewriteCond %{HTTPS} off - # RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] + # ======Redirect to HTTPS + RewriteCond %{HTTP_HOST} !=localhost + RewriteCond %{HTTP_HOST} !=127.0.0.1 + RewriteCond %{HTTPS} off + RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] - # # Avoid redirect staging sites - # RewriteCond %{HTTP_HOST} !=localhost - # RewriteCond %{HTTP_HOST} !=127.0.0.1 - # RewriteCond %{HTTP_HOST} !=staging.openhistoricalmap.org - # RewriteCond %{HTTP_HOST} !^www\. [NC] - # RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] + # ======Redirect to wwww openhistoricalmap.org + RewriteCond %{HTTP_HOST} =openhistoricalmap.org + RewriteCond %{HTTP_HOST} !^www\. [NC] + RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] + # + # CGIPassAuth On + # # ======Redirect trafict to CGIMAP==== # Rules to redirect to port 81 + RewriteCond %{HTTP_HOST} =staging.openhistoricalmap.org RewriteCond %{REQUEST_URI} ^/api/0\.6/map RewriteRule ^.*$ http://127.0.0.1:81%{REQUEST_URI} [P,L] # Existing rewrites RewriteRule ^0\.6/map$ - [L,H=fcgi:127.0.0.1:81] RewriteRule ^0\.6/(nodes|ways|relations)$ - [L,H=fcgi:127.0.0.1:81] RewriteRule ^0\.6/(way|relation)/([^/]+)/full$ - [L,H=fcgi:127.0.0.1:81] - - # If no match found, fall through to port 80 - RewriteCond %{REQUEST_METHOD} ^(GET|HEAD)$ - RewriteRule ^0\.6/(node|way|relation)/([^/]+)$ - [L,H=fcgi:127.0.0.1:80] # Relax Apache security settings @@ -46,4 +38,4 @@ Allow from all Options -MultiViews - \ No newline at end of file + diff --git a/images/web/start.sh b/images/web/start.sh index 17a6c216..97f5a4f6 100755 --- a/images/web/start.sh +++ b/images/web/start.sh @@ -62,8 +62,15 @@ while "$flag" = true; do bundle exec rails db:migrate # Start lighttpd and cgimap + /usr/local/bin/openstreetmap-cgimap \ + --port=8000 \ + --instances=30 \ + --dbname=$POSTGRES_DB \ + --host=$POSTGRES_HOST \ + --username=$POSTGRES_USER \ + --password=$POSTGRES_PASSWORD \ + --logfile log/cgimap.log & /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf - # Start the delayed jobs queue worker and Start the app bundle exec rake jobs:work & apachectl -k start -DFOREGROUND