昨日記事にあげた Ptorx だが、Nginx で妥協したのがモヤモヤするので、Apache でも構成してみた。
が、どうしても、Nginx の try_files ディレクティブと同等のことが、サイト設定だけでは完結せず、以下のような内容の .htaccess を
web/dist/accownt/web/distccashcow/web/distyalcs/web/dist
に配置せざるをえなかった。知識の乏しさに泣きそうになる。
<Files ".htaccess">
Require all denied
</Files>
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [L]
その上でサイト設定は以下のようにした。
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
RewriteEngine On
RewriteCond %{SERVER_NAME} =www.example.com [OR]
RewriteCond %{SERVER_NAME} =example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName example.com
ServerAlias www.example.com
ServerAdmin webmaster@example.com
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1$1 [R=301,L]
RequestHeader set Strict-Transport-Security "max-age=31536000; includeSubDomains"
RequestHeader set X-XSS-Protection "1; mode=block"
RequestHeader set X-Content-Type-Options nosniff
Alias /accownt/static/ /srv/ptorx/ptorx/accownt/web/dist/
Alias /accownt/ /srv/ptorx/ptorx/accownt/web/dist/
<Directory "/srv/ptorx/ptorx/accownt/web/dist">
AllowOverride All
Require all granted
</Directory>
<Location /accownt/api>
ProxyPass http://127.0.0.1:2074/api
ProxyPassReverse http://127.0.0.1:2074/api
</Location>
Alias /ccashcow/static/ /srv/ptorx/ptorx/ccashcow/web/dist/
Alias /ccashcow/ /srv/ptorx/ptorx/ccashcow/web/dist/
<Directory "/srv/ptorx/ptorx/ccashcow/web/dist">
AllowOverride All
Require all granted
</Directory>
<Location /ccashcow/api>
ProxyPass http://127.0.0.1:2075/api
ProxyPassReverse http://127.0.0.1:2075/api
</Location>
Alias /yalcs/static/ /srv/ptorx/yalcs/ccashcow/web/dist/
Alias /yalcs/ /srv/ptorx/ptorx/yalcs/web/dist/
<Directory "/srv/ptorx/ptorx/yalcs/web/dist">
AllowOverride All
Require all granted
</Directory>
<Location /yalcs/api>
ProxyPass http://127.0.0.1:2079/api
ProxyPassReverse http://127.0.0.1:2079/api
</Location>
<Location /api/6>
ProxyPass http://127.0.0.1:2070/api/6
ProxyPassReverse http://127.0.0.1:2070/api/6
</Location>
Alias /icon.png /srv/ptorx/ptorx/mobile/icon.png
<Files "/srv/ptorx/ptorx/mobile/icon.png">
Require all granted
</Files>
Alias /static/ /srv/ptorx/ptorx/web/dist/
DocumentRoot /srv/ptorx/ptorx/web/dist/
<Directory "/srv/ptorx/ptorx/web/dist">
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
</IfModule>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet