Note: Please go to docs.rightscale.com to access the current RightScale documentation set. Also, feel free to Chat with us!
Home > FAQs > How do I modify the apache vhost file?

How do I modify the apache vhost file?

Background Information

We have built a set of tools that assist in creating vhost configuration files. ServerTemplates that use these tools have a RightScript enabled that makes a call to the tools with specific parameters that create a generic vhost configuration. This configuration will work for most users, but you may find that you need to customize it in order to meet your particular requirements. There are two ways to do this discussed in this FAQ.

 


Answer

Method 1

The first way is to modify the default RightScript to change the parameters that are given to the tools. Here is a list of all of the options that may be given:

 

Required Parameters:

-t http|https] -- Predefined template to use
-s | --server SERVER_NAME -- Virtual host name
-d | --document-root DOCUMENT_ROOT -- Document Root of the virtual host

Optional parameters:

[-p | --port SERVER_PORT ] -- Listen port of the vhost (Default: 80)
[-m | --maintenance MAINTENANCE_URI ] -- Maintenance URI to show if the page exists (based on document root)
[-r | --home-redirect HOME_REDIRECT_URL ] -- URL where to redirect '/' requests (Default: no redirect)
[-k | --server-status on|off ] -- Enable or disable Apache's server status for 127.0.0.1 sources only (Default: on )
[-c | --canonical-hostname on|off ] -- Enable or disable redirecting ip/aliases to the canonical vhost name (Default: on)
[-f | --serve-local-files on|off ] -- Enable or disable serving local files if they exist (instead of proxying the requests). (Default: on)
[-l | --log-dir LOG_DIR ] -- Override for the directory logs of the vhost
[-v emerg|alert|crit|error|warn|notice|info|debug ] -- Override of the log_level directive for the vhost
[-n | --next-hop TARGET:PORT ] -- Target definition where to proxy requests. (Default: 127.0.0.1:85 )
[-a | --attached-certs-dir ATTACH_DIR] -- Directory where to look for the certificates
[-S | --redirect-all-to-ssl on|off ] -- Force all http requests to be redirected to https (except status, and local files if enabled). (Default: off)
[-P | --php on|off ] -- Enable or disable php bindings for this vhost. (Default: off)

 

Method 2

If the customizations that you need is one of these options, then we recommend editing the default script and adjusting them as necessary. In cases where you need additional customization of the vhost file (like adding rewrite rules), we insert four tags into the file at specific locations so that you can search for these tags and add your customization at the proper place. The tags are:

# <CUSTOM RULES BEFORE ANYTHING BEGIN>
# <CUSTOM RULES BEFORE ANYTHING END>
# <CUSTOM RULES BEFORE FORWARDING BEGIN>
# <CUSTOM RULES BEFORE FORWARDING END>

 

 Here is an example script that adds a new rewrite rule after a tag:

#!/bin/bash -e

#create a temporary file to hold the new rewrite rules
cat<<EOF >/tmp/rs_tmp_my_rule
    # Redirect to another machine
    RewriteRule ^/somepath/(.*)\$ http://mymachine.com/\$1 [P,QSA,L]
EOF

#Read the above snippet in all the vhost file.
sed -i.orig '/# <CUSTOM RULES BEFORE FORWARDING BEGIN>/r/tmp/rs_tmp_my_rule' /etc/httpd/rightscale.d/*-my.host.com.vhost

#remove the temp file
rm /tmp/rs_tmp_my_rule

 

You must to post a comment.
Last modified
21:26, 16 May 2013

Tags

Classifications

This page has no classifications.

Announcements

None


© 2006-2014 RightScale, Inc. All rights reserved.
RightScale is a registered trademark of RightScale, Inc. All other products and services may be trademarks or servicemarks of their respective owners.