From 2535e31f798564ff5a9058f5a255992fb1cf60fd Mon Sep 17 00:00:00 2001 From: Rub21 Date: Wed, 20 Sep 2023 19:31:51 -0500 Subject: [PATCH] Redirect request to cgimap --- images/web/Dockerfile | 2 +- images/web/config/lighttpd.conf | 60 ++++++++++++++++++++++--------- images/web/config/production.conf | 32 +++++++++++------ images/web/start.sh | 11 ++---- values.staging.template.yaml | 2 +- 5 files changed, 68 insertions(+), 39 deletions(-) diff --git a/images/web/Dockerfile b/images/web/Dockerfile index 96e5c0a5..dc02049b 100644 --- a/images/web/Dockerfile +++ b/images/web/Dockerfile @@ -106,7 +106,7 @@ RUN chown -R www-data: $workdir # Add settings ADD config/settings.yml $workdir/config/ -ADD config/lighttpd.conf $workdir/config/ +ADD config/lighttpd.conf etc/lighttpd/lighttpd.conf COPY start.sh $workdir/ diff --git a/images/web/config/lighttpd.conf b/images/web/config/lighttpd.conf index c21db904..1a2088be 100644 --- a/images/web/config/lighttpd.conf +++ b/images/web/config/lighttpd.conf @@ -1,20 +1,38 @@ # default document-root -server.document-root = "/openstreetmap/cgimap/" +server.document-root = "/var/www/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" ) - -accesslog.filename = "/dev/stdout" -server.errorlog = "/dev/stderr" +server.modules = ( "mod_access", "mod_rewrite", "mod_fastcgi", "mod_proxy", "mod_alias", "mod_openssl") # 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" @@ -27,18 +45,14 @@ mimetype.assign = ( ".png" => "image/png" ) -# 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" - ) +$HTTP["request-method"] != "OPTIONS" { + # Your existing redirect condition and rule here, for example: + $HTTP["scheme"] == "http" { + url.redirect = (".*" => "https://%0$0") + } } -#debug.log-request-handling = "enable" +debug.log-request-handling = "enable" $HTTP["request-method"] == "GET" { url.rewrite-once = ( @@ -76,8 +90,20 @@ $HTTP["url"] =~ "^/(?!(dispatch\.map))" { fastcgi.debug = 1 fastcgi.server = ( ".map" => - (( "host" => "127.0.0.1", - "port" => 8000, + (( "socket" => "/tmp/map-fastcgi.socket", + "bin-path" => "/usr/local/bin/openstreetmap-cgimap", + "docroot" => "/", + "min-procs" => 1, + "max-procs" => 1, "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 + ) )) ) + +server.errorlog = "/var/log/lighttpd/error.log" diff --git a/images/web/config/production.conf b/images/web/config/production.conf index d0a1c205..1f214dbf 100644 --- a/images/web/config/production.conf +++ b/images/web/config/production.conf @@ -4,18 +4,28 @@ DocumentRoot /var/www/public PassengerRuby /usr/bin/ruby RewriteEngine On + RewriteCond %{HTTP:X-Forwarded-Proto} =http - # Development mode in case domain is localhost - # Rewrite to HTTPS - RewriteCond %{HTTP_HOST} !=localhost - RewriteCond %{HTTPS} off - RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] - # Rewrite to www. [NC] is a case-insensitive match - RewriteCond %{HTTP_HOST} !=localhost - # Avoid redirect staging sites - RewriteCond %{HTTP_HOST} !=staging.openhistoricalmap.org - RewriteCond %{HTTP_HOST} !^www\. [NC] - RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] + 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] + + # # Skip redirect for other methods + # RewriteCond %{REQUEST_METHOD} !OPTIONS + # RewriteCond %{HTTPS} off + # RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] + + # # 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 trafict to CGIMAP==== # Rules to redirect to port 81 diff --git a/images/web/start.sh b/images/web/start.sh index a7118bcc..17a6c216 100755 --- a/images/web/start.sh +++ b/images/web/start.sh @@ -61,15 +61,8 @@ while "$flag" = true; do bundle exec rails db:migrate - # Start CGImap - /usr/sbin/lighttpd -f config/lighttpd.conf - /usr/local/bin/openstreetmap-cgimap \ - --port=8000 \ - --instances=30 \ - --dbname=$POSTGRES_DB \ - --host=$POSTGRES_HOST \ - --username=$POSTGRES_USER \ - --password=$POSTGRES_PASSWORD & + # Start lighttpd and cgimap + /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf # Start the delayed jobs queue worker and Start the app bundle exec rake jobs:work & diff --git a/values.staging.template.yaml b/values.staging.template.yaml index ec2bac01..3847bf10 100644 --- a/values.staging.template.yaml +++ b/values.staging.template.yaml @@ -132,7 +132,7 @@ osm-seed: maxReplicas: 10 cpuUtilization: 80 cgimap: - enabled: false + enabled: true # ==================================================================================================== # Variables for memcached. Memcached is used to store session cookies # ====================================================================================================