Skip to content

Commit

Permalink
Redirect request to cgimap
Browse files Browse the repository at this point in the history
  • Loading branch information
Rub21 committed Sep 21, 2023
1 parent 5ca7e58 commit 2535e31
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 39 deletions.
2 changes: 1 addition & 1 deletion images/web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/

Expand Down
60 changes: 43 additions & 17 deletions images/web/config/lighttpd.conf
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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 = (
Expand Down Expand Up @@ -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"
32 changes: 21 additions & 11 deletions images/web/config/production.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 2 additions & 9 deletions images/web/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 &
Expand Down
2 changes: 1 addition & 1 deletion values.staging.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
# ====================================================================================================
Expand Down

0 comments on commit 2535e31

Please sign in to comment.