• Document Up to Date

Configuring Apache Virtual Host for Production

This section will show you a sample Apache virtual host configuration for your CrafterCMS site.

Here’s the sample configuration for setting up a vhost for production:

 1<VirtualHost *:80>
 2    ServerName example.com
 3
 4    # Path where your actual CrafterCMS site resides on the server
 5    DocumentRoot /path_to_crafter/crafter/data/repos/sites/mysite
 6
 7    RewriteEngine On
 8
 9    # Assign crafter site/tenant for this vhost
10    # Remember to change mysite to your actual site name
11    RewriteRule (.*) $1?crafterSite=mysite [QSA,PT]
12
13    # Block outside access to management services
14    RewriteRule ^/api/1/cache / [NC,PT,L]
15    RewriteRule ^/api/1/site/mappings / [NC,PT,L]
16    RewriteRule ^/api/1/site/cache / [NC,PT,L]
17    RewriteRule ^/api/1/site/context/destroy / [NC,PT,L]
18    RewriteRule ^/api/1/site/context/rebuild / [NC,PT,L]
19
20    # Take all inbound URLs and lower case them before proxying to Crafter Engine
21    #     Crafter Studio forces all URL path names to be lower case to have a consistent naming pattern on the server for the files
22    #     Using the rewrite rule below, the URL the user sees can be any (upper and/or lower) case
23    RewriteCond %{REQUEST_URI} !^/static-assets/.*$ [NC]
24    RewriteCond %{REQUEST_URI} !^/api/.*$ [NC]
25    RewriteMap lc int:tolower
26    RewriteRule ^/(.*)$ /${lc:$1}
27
28    ProxyPreserveHost On
29
30    # Don't send static asset requests to Engine
31    ProxyPass /static-assets !
32
33    # Send requests to Engine's Tomcat
34    ProxyPass / ajp://localhost:9009/
35    ProxyPassReverse / ajp://localhost:9009/
36
37    # This is where errors related to this virtual host are stored
38    ErrorLog ${APACHE_LOG_DIR}/mysite-error.log
39    # This is where access logs are stored
40    CustomLog ${APACHE_LOG_DIR}/mysite-access.log combined
41  </VirtualHost>

For more information on Apache Virtual Host, see: http://httpd.apache.org/docs/current/vhosts/index.html