Skip to content

Instantly share code, notes, and snippets.

@kberov
Created June 20, 2019 19:10
Show Gist options
  • Save kberov/2c3d9fc27bbdadb4676e09ae9e612a05 to your computer and use it in GitHub Desktop.
Save kberov/2c3d9fc27bbdadb4676e09ae9e612a05 to your computer and use it in GitHub Desktop.
# /etc/apache2/sites-enabled/001-dev.slovo.conf
<VirtualHost *:80>
ServerName dev.slovo.bg
ServerAdmin webmaster@dev.slovo
DocumentRoot /home/berov/opt/dev.slovo.bg
<Directory "/home/berov/opt/dev.slovo.bg">
AllowOverride All
Require all granted
</Directory>
# LogLevel info ssl:warn
LogLevel info authz_core:error rewrite:debug
ErrorLog ${APACHE_LOG_DIR}/dev.slovo.error.log
CustomLog ${APACHE_LOG_DIR}/dev.slovo.access.log combined
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
#.htaccess
# Apache 2 .htaccess configuration for Slovo.
# Generated by Slovo::Command::Author::generate::a2htaccess using template a2htaccess from DATA section.
# Note!! If you run again `slovo generate a2htaccess` this file will NOT be
# rewritten. Note! Not sure if the produced .htacces will work fine for you so
# make sure to test locally first.
# Uncomment the following line when going live or regenerate slovo.cgi:
# slovo generate cgi_script -f slovo.cgi -m production
# SetEnv HTTP_MOJO_MODE production
# use utf-8 encoding for anything served text/plain or text/html
AddDefaultCharset utf-8
# Protect files and directories from prying eyes.
<FilesMatch "(templ/|etc/|lib/|log/|t/|_build/|cover_db/|\.(pmc?|ep|conf|log|t|bak|yml|sqlite|sql)|READM.+|MANIF.+|Build.PL|Build|Makefi.+)$">
#2.2 configuration:
<IfModule !mod_authz_core.c>
Order deny,allow
Deny from all
</IfModule>
#2.4 configuration:
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
</FilesMatch>
Options +Indexes +FollowSymLinks +ExecCGI
# Requires mod_expires to be enabled.
<IfModule mod_expires.c>
# Enable expirations.
ExpiresActive On
ExpiresDefault "access plus 1 month"
<IfModule mod_headers.c>
Header append Cache-Control "public"
</IfModule>
<FilesMatch slovo.cgi>
# Do not allow slovo responses to be cached unless they explicitly send
# cache headers themselves.
ExpiresActive Off
</FilesMatch>
</IfModule>
<Files ~ "^(slovo.cgi)$">
SetHandler cgi-script
</Files>
# Some more security. Redefine the mime type for the most common types of scripts
AddType text/plain .shtml .php .php3 .phtml .phtm .pl .py
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
# Do not apply rules when requesting "favicon.ico"
RewriteCond %{REQUEST_FILENAME} favicon.ico [NC]
RewriteRule .* - [S=14]
# Do not apply rules when requesting "slovo.cgi"
RewriteCond %{SCRIPT_FILENAME} slovo.cgi [NC]
RewriteRule .* - [S=14]
# Redirect all requests for Slovo static files to respective domain's public/ directory.
# /css/fonts.css -> /domove/t.com/public/css/fonts.css
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^(www|qa|dev)\.(.+)$ [NC]
RewriteRule ^((?:css|img|js|fonts)/.+)$ /slovo/domove/%2/public/$1 [NE,END]
#t.com/about-en-us.html -> t.com/domove/t.com/public/cached/about-en-us.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^(www|qa|dev)\.(.+)$ [NC]
RewriteRule ^(.+(?!\.cgi).+\.html)$ /slovo/domove/%2/public/cached/$1 [NS,NE,END]
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule (.+(?!\.cgi).+) /slovo/slovo.cgi/$1 [L,NE]
</IfModule>
#
# Make Slovo handle any 404 errors.
ErrorDocument 404 /slovo/slovo.cgi%{REQUEST_URI}
DirectoryIndex /slovo/slovo.cgi
@kberov
Copy link
Author

kberov commented Jun 20, 2019

Problems:
Mojo generates url escaped links - tha is fine

21:39:23|berov@Skylake:Slovo$ perl -MMojo::Util=url_unescape,encode,decode -E 'say url_unescape("/slovo/slovo.cgi/%D1%BF%D0%BD%D0%BE%D1%81%D0%BD%D0%BE.bg-bg.html")'
/slovo/slovo.cgi/ѿносно.bg-bg.html

but passing thoou apache, mojo sees the following:

21:57:33|berov@Skylake:Slovo$ perl -MMojo::Util=url_unescape,encode,decode -E 'say url_unescape("/%C3%91%C2%BF%C3%90%C2%BD%C3%90%C2%BE%C3%91%C2%81%C3%90%C2%BD%C3%90%C2%BE.bg-bg.html")'
/ѿно�но.bg-bg.html

from the error.log:

[2019-06-20 21:57:56.53814] [5513] [debug] GET "/%C3%91%C2%BF%C3%90%C2%BD%C3%90%C2%BE%C3%91%C2%81%C3%90%C2%BD%C3%90%C2%BE.bg-bg.html" (2f3e4194)
[

@kberov
Copy link
Author

kberov commented Jun 20, 2019

rewrite:trace1

[Thu Jun 20 22:28:09.299909 2019] [rewrite:trace1] [pid 5743:tid 140249590126336] mod_rewrite.c(482): [client 127.0.0.1:48032] 127.0.0.1 - - [dev.slovo.bg/sid#7f8e84238028][rid#7f8e7c55d0a0/initial] [perdir /home/berov/opt/dev.slovo.bg/] pass through /home/berov/opt/dev.slovo.bg/slovo/slovo.cgi, referer: http://dev.slovo.bg/slovo/slovo.cgi
[Thu Jun 20 22:28:09.300003 2019] [rewrite:trace1] [pid 5743:tid 140249590126336] mod_rewrite.c(482): [client 127.0.0.1:48032] 127.0.0.1 - - [dev.slovo.bg/sid#7f8e84238028][rid#7f8e7c5890a0/subreq] [perdir /home/berov/opt/dev.slovo.bg/] pass through /home/berov/opt/dev.slovo.bg/\xd1\xbf\xd0\xbd\xd0\xbe\xd1\x81\xd0\xbd\xd0\xbe.bg-bg.html, referer: http://dev.slovo.bg/slovo/slovo.cgi
[Thu Jun 20 22:28:09.833808 2019] [rewrite:trace1] [pid 5743:tid 140249573340928] mod_rewrite.c(482): [client 127.0.0.1:48032] 127.0.0.1 - - [dev.slovo.bg/sid#7f8e84238028][rid#7f8e7c5870a0/initial] [perdir /home/berov/opt/dev.slovo.bg/] pass through /home/berov/opt/dev.slovo.bg/slovo/slovo.cgi, referer: http://dev.slovo.bg/slovo/slovo.cgi/%D1%BF%D0%BD%D0%BE%D1%81%D0%BD%D0%BE.bg-bg.html
[Thu Jun 20 22:28:09.833808 2019] [rewrite:trace1] [pid 5742:tid 140249128756992] mod_rewrite.c(482): [client 127.0.0.1:48038] 127.0.0.1 - - [dev.slovo.bg/sid#7f8e84238028][rid#7f8e7c7b10a0/initial] [perdir /home/berov/opt/dev.slovo.bg/] pass through /home/berov/opt/dev.slovo.bg/slovo/slovo.cgi, referer: http://dev.slovo.bg/slovo/slovo.cgi/%D1%BF%D0%BD%D0%BE%D1%81%D0%BD%D0%BE.bg-bg.html
[Thu Jun 20 22:28:09.833899 2019] [rewrite:trace1] [pid 5742:tid 140249128756992] mod_rewrite.c(482): [client 127.0.0.1:48038] 127.0.0.1 - - [dev.slovo.bg/sid#7f8e84238028][rid#7f8e7c7bd0a0/subreq] [perdir /home/berov/opt/dev.slovo.bg/] pass through /home/berov/opt/dev.slovo.bg/mojo, referer: http://dev.slovo.bg/slovo/slovo.cgi/%D1%BF%D0%BD%D0%BE%D1%81%D0%BD%D0%BE.bg-bg.html
[Thu Jun 20 22:28:09.833994 2019] [rewrite:trace1] [pid 5743:tid 140249573340928] mod_rewrite.c(482): [client 127.0.0.1:48032] 127.0.0.1 - - [dev.slovo.bg/sid#7f8e84238028][rid#7f8e7c55d0a0/subreq] [perdir /home/berov/opt/dev.slovo.bg/] pass through /home/berov/opt/dev.slovo.bg/mojo, referer: http://dev.slovo.bg/slovo/slovo.cgi/%D1%BF%D0%BD%D0%BE%D1%81%D0%BD%D0%BE.bg-bg.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment