Avoiding /opencms/opencms in the URL (apache + mod proxy)

From OpenCms Wiki
(Difference between revisions)
Jump to: navigation, search
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
If you are running OpenCms (7.5 or greater) in Tomcat using an Apache front end (WITH MOD_PROXY, NOT MOD_JK), there are four basic steps to configuring your environment for avoiding the /opencms/opencms in the URL:
+
If you are running OpenCms (7.5 or greater) as '''''opencms''''' web application in Tomcat using an Apache front end (WITH MOD_PROXY, NOT MOD_JK), there are four basic steps to configuring your environment for avoiding the /opencms/opencms in the URL:
  
 
== Add site information to OpenCMS's configuration ==
 
== Add site information to OpenCMS's configuration ==
 +
 
In order to make your new site available within OpenCMS, we need to modify the opencms-system.xml configuration file, located in ${TOMCAT_HOME}\webapps\${OPENCMS_WEBAPP}\WEB-INF\config\.
 
In order to make your new site available within OpenCMS, we need to modify the opencms-system.xml configuration file, located in ${TOMCAT_HOME}\webapps\${OPENCMS_WEBAPP}\WEB-INF\config\.
  
Line 13: Line 14:
 
== Adjust OpenCms automatic link generation (static export, module-resources) ==
 
== Adjust OpenCms automatic link generation (static export, module-resources) ==
  
This configuration is only valid if OpenCms is installed as the ROOT application in Tomcat. Edit the file “WEB-INF/config/opencms-importexport.xml” in your OpenCms installation to look as follows:
+
Edit the file “WEB-INF/config/opencms-importexport.xml” in your OpenCms installation to look as follows:
  
 
  <rendersettings>
 
  <rendersettings>
Line 59: Line 60:
 
  NameVirtualHost *:80
 
  NameVirtualHost *:80
  
<VirtualHost *:80>
+
<pre>
 +
<VirtualHost *:80>
 +
 
 
   ServerName www.example.com
 
   ServerName www.example.com
 
   ServerAdmin webmaster@opencms.org
 
   ServerAdmin webmaster@opencms.org
   DocumentRoot "C:\dev\Tomcat6.0\webapps\opencms"
+
   DocumentRoot "${OPENCMS_HOME}"
 +
 
 
   # Allow accessing the document root directory
 
   # Allow accessing the document root directory
   <Directory "C:\dev\Tomcat6.0\webapps\opencms">
+
   <Directory "${OPENCMS_HOME}">
 
     Options FollowSymlinks
 
     Options FollowSymlinks
 
     AllowOverride All
 
     AllowOverride All
Line 70: Line 74:
 
     Allow from all
 
     Allow from all
 
   </Directory>
 
   </Directory>
   ErrorLog C:\dev\Apache2.0\Apache2\logs\errors_www.example.com.log
+
 
   CustomLog C:\dev\Apache2.0\Apache2\logs\access_www.example.com.log combined
+
   ErrorLog logs/errors_www.example.com.log
 +
   CustomLog logs/access_www.example.com.log combined
 +
 
 
   RewriteEngine On
 
   RewriteEngine On
   RewriteLog C:\dev\Apache2.0\Apache2\logs\rewrite_www.example.com.log
+
   RewriteLog logs/rewrite_www.example.com.log
 
   RewriteLogLevel 9
 
   RewriteLogLevel 9
 +
 
   RewriteCond      %{REQUEST_URI}                                            ^/opencms/export/(.*)  [NC]
 
   RewriteCond      %{REQUEST_URI}                                            ^/opencms/export/(.*)  [NC]
 
   RewriteCond      "%{DOCUMENT_ROOT}%{REQUEST_FILENAME}"                    !-f
 
   RewriteCond      "%{DOCUMENT_ROOT}%{REQUEST_FILENAME}"                    !-f
 
   RewriteCond      "%{DOCUMENT_ROOT}%{REQUEST_FILENAME}/index_export.html"  !-f
 
   RewriteCond      "%{DOCUMENT_ROOT}%{REQUEST_FILENAME}/index_export.html"  !-f
 
   RewriteRule      .*                                                        http://127.0.0.1:8081/opencms/opencms/handle404?exporturi=%{REQUEST_URI}&%{QUERY_STRING} [P]
 
   RewriteRule      .*                                                        http://127.0.0.1:8081/opencms/opencms/handle404?exporturi=%{REQUEST_URI}&%{QUERY_STRING} [P]
 +
 
   # If the request starts with /${WEBAPP_NAME}/resources, delete the /${WEBAPP_NAME} prefix
 
   # If the request starts with /${WEBAPP_NAME}/resources, delete the /${WEBAPP_NAME} prefix
 
   RewriteCond %{REQUEST_URI}                          ^/opencms/resources/.*$
 
   RewriteCond %{REQUEST_URI}                          ^/opencms/resources/.*$
 
   RewriteRule ^/opencms/(.*)$                          /$1 [PT]
 
   RewriteRule ^/opencms/(.*)$                          /$1 [PT]
 +
 
   # Also redirect all other 404 errors to OpenCms
 
   # Also redirect all other 404 errors to OpenCms
 
   ErrorDocument    404                                /system/shared/handle404.html
 
   ErrorDocument    404                                /system/shared/handle404.html
 +
 
   RedirectPermanent /opencms/opencms/                  http://www.example.com/
 
   RedirectPermanent /opencms/opencms/                  http://www.example.com/
 
   ProxyPass        /opencms/opencms/                  !
 
   ProxyPass        /opencms/opencms/                  !
 +
 
   ProxyPass        /opencms/resources/                !
 
   ProxyPass        /opencms/resources/                !
 
   ProxyPass        /opencms/export/                  !
 
   ProxyPass        /opencms/export/                  !
 +
 
   ProxyPass        /                                  http://127.0.0.1:8081/opencms/opencms/
 
   ProxyPass        /                                  http://127.0.0.1:8081/opencms/opencms/
 
   ProxyPassReverse  /                                  http://127.0.0.1:8081/opencms/opencms/
 
   ProxyPassReverse  /                                  http://127.0.0.1:8081/opencms/opencms/
</VirtualHost>
+
 
 +
</VirtualHost>
 +
</pre>
  
 
The ServerName is the hostname that'll be matched against any incoming requests -- it doesn't '''have''' to match your Tomcat proxyName and OpenCMS site server, but it'll be less confusing to troubleshoot later if it does. The URL used in the ProxyPass and ProxyPassReverse lines should point to the Tomcat connector you configured in the previous step.
 
The ServerName is the hostname that'll be matched against any incoming requests -- it doesn't '''have''' to match your Tomcat proxyName and OpenCMS site server, but it'll be less confusing to troubleshoot later if it does. The URL used in the ProxyPass and ProxyPassReverse lines should point to the Tomcat connector you configured in the previous step.

Latest revision as of 13:13, 16 February 2010

If you are running OpenCms (7.5 or greater) as opencms web application in Tomcat using an Apache front end (WITH MOD_PROXY, NOT MOD_JK), there are four basic steps to configuring your environment for avoiding the /opencms/opencms in the URL:

Contents

Add site information to OpenCMS's configuration

In order to make your new site available within OpenCMS, we need to modify the opencms-system.xml configuration file, located in ${TOMCAT_HOME}\webapps\${OPENCMS_WEBAPP}\WEB-INF\config\.

Find the <sites> node of opencms-system.xml and modify it as follows:

<sites>
  <workplace-server>http://www.example.com</workplace-server>
  <default-uri>/</default-uri>
  <site server="http://www.example.com" uri="/sites/default/" />
</sites>

Adjust OpenCms automatic link generation (static export, module-resources)

Edit the file “WEB-INF/config/opencms-importexport.xml” in your OpenCms installation to look as follows:

<rendersettings>
  <rfs-prefix>${CONTEXT_NAME}/export</rfs-prefix>
  <vfs-prefix>/</vfs-prefix>
  ...
</rendersettings>

Defining the tomcat connectors

edit the ${TOMCAT_HOME}/conf/server.xml and define two connectors like:

<Connector port="8009"
 address="127.0.0.1"
 protocol="AJP/1.3"
 redirectPort="8443"
 emptySessionPath="true"
 enableLookups="false"/>
<Connector port="8081"
 maxHttpHeaderSize="8192"
 maxThreads="150"
 minSpareThreads="25"
 maxSpareThreads="75"
 enableLookups="false"
 redirectPort="8443"
 acceptCount="100"
 proxyName="www.example.com"
 proxyPort="80"
 useBodyEncodingForURI="true"
 connectionTimeout="20000"
 disableUploadTimeout="true"
 emptySessionPath="true" />

The port attribute (8081 in the example above) should be unique within your server.xml. The proxyName attribute should match the server attribute in your site definition in opencms-system.xml above.

Once you've made this change and restarted Tomcat, you should be able to go to http://YourTomcatServer:8081/opencms/opencms/ and see your MyNewSite content.

Add site information to Apache's configuration

Finally, we need to add a virtual host to Apache to handle requests for your new site (etc/apache2/sites-enabled/www.example.com)

LoadModule rewrite_module modules/mod_rewrite.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
NameVirtualHost *:80
<VirtualHost *:80>
  
  ServerName www.example.com
  ServerAdmin webmaster@opencms.org
  DocumentRoot "${OPENCMS_HOME}"
  
  # Allow accessing the document root directory
  <Directory "${OPENCMS_HOME}">
    Options FollowSymlinks
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>

  ErrorLog logs/errors_www.example.com.log
  CustomLog logs/access_www.example.com.log combined

  RewriteEngine On
  RewriteLog logs/rewrite_www.example.com.log
  RewriteLogLevel 9

  RewriteCond       %{REQUEST_URI}                                            ^/opencms/export/(.*)  [NC]
  RewriteCond       "%{DOCUMENT_ROOT}%{REQUEST_FILENAME}"                     !-f
  RewriteCond       "%{DOCUMENT_ROOT}%{REQUEST_FILENAME}/index_export.html"   !-f
  RewriteRule       .*                                                        http://127.0.0.1:8081/opencms/opencms/handle404?exporturi=%{REQUEST_URI}&%{QUERY_STRING} [P]

  # If the request starts with /${WEBAPP_NAME}/resources, delete the /${WEBAPP_NAME} prefix
  RewriteCond %{REQUEST_URI}                           ^/opencms/resources/.*$
  RewriteRule ^/opencms/(.*)$                          /$1 [PT]

  # Also redirect all other 404 errors to OpenCms
  ErrorDocument     404                                /system/shared/handle404.html

  RedirectPermanent /opencms/opencms/                  http://www.example.com/
  ProxyPass         /opencms/opencms/                  !

  ProxyPass         /opencms/resources/                !
  ProxyPass         /opencms/export/                   !

  ProxyPass         /                                  http://127.0.0.1:8081/opencms/opencms/
  ProxyPassReverse  /                                  http://127.0.0.1:8081/opencms/opencms/

</VirtualHost>

The ServerName is the hostname that'll be matched against any incoming requests -- it doesn't have to match your Tomcat proxyName and OpenCMS site server, but it'll be less confusing to troubleshoot later if it does. The URL used in the ProxyPass and ProxyPassReverse lines should point to the Tomcat connector you configured in the previous step.

To add more sites, you need to add NameVirtualHost *:80 before the first <VirtualHost>; otherwise, apache will report [warn] _default_ VirtualHost overlap on port 80, the first has precedence.

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox