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

From OpenCms Wiki
(Difference between revisions)
Jump to: navigation, search
 
(16 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 ==
 +
 
 +
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 ==
 
== Defining the tomcat connectors ==
Line 19: Line 40:
 
   redirectPort="8443"
 
   redirectPort="8443"
 
   acceptCount="100"
 
   acceptCount="100"
   proxyName="pre.mrmbe.es"
+
   proxyName="www.example.com"
 
   proxyPort="80"
 
   proxyPort="80"
 
   useBodyEncodingForURI="true"
 
   useBodyEncodingForURI="true"
Line 25: Line 46:
 
   disableUploadTimeout="true"
 
   disableUploadTimeout="true"
 
   emptySessionPath="true" />
 
   emptySessionPath="true" />
 
 
== 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 <opencmsroot>/WEB-INF/config/.
 
 
Find the section of opencms-system.xml that looks like:
 
  <sites>
 
    <workplace-server>http://www.mysite.com:8080</workplace-server>
 
    <default-uri>/sites/default/</default-uri>
 
    <site server="www.mysite.com" uri="/sites/default/"/>
 
  </sites>
 
 
and add another site definition as follows:
 
    <site server="www.mynewsite.com" uri="/sites/MyNewSite/"/>
 
 
This tells OpenCMS that when it receives a request for www.mynewsite.com, it should serve that request out of the MyNewSite container.
 
 
== Add site information to Tomcat's configuration ==
 
In order for Tomcat to correctly route web requests to the correct site in OpenCMS, we need to modify the server.xml configuration file, located in <tomcatroot>/conf.
 
 
Find the section of server.xml that looks like:
 
    <Connector port="8080" maxHttpHeaderSize="8192"
 
              maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
 
              enableLookups="false" redirectPort="8443" acceptCount="100"
 
              connectionTimeout="20000" disableUploadTimeout="true" />
 
 
and add another connector definition as follows:
 
    <Connector port="8081" maxHttpHeaderSize="8192"
 
              maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
 
              enableLookups="false" redirectPort="8443" acceptCount="100" 
 
              proxyName="www.mynewsite.com" proxyPort="80"
 
              connectionTimeout="20000" disableUploadTimeout="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.
 
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.
Line 63: Line 52:
  
 
== Add site information to Apache's configuration ==
 
== Add site information to Apache's configuration ==
Finally, we need to add a virtual host to Apache to handle requests for your new site.  This will be done in httpd.conf (location varies depending on the layout under which you installed Apache -- on my system, it's in /usr/local/etc/apache). In Apache 1.3.x, the virtual host configuration will look something like:
+
Finally, we need to add a virtual host to Apache to handle requests for your new site (etc/apache2/sites-enabled/www.example.com)
  
  <VirtualHost Server.IPAddress.Goes.Here>
+
LoadModule rewrite_module modules/mod_rewrite.so
      DocumentRoot /usr/local/www/htdocs
+
LoadModule proxy_module modules/mod_proxy.so
      ServerName www.mynewsite.com
+
LoadModule proxy_http_module modules/mod_proxy_http.so
      ProxyPass / http://localhost:8081/opencms/opencms/
+
      ProxyPassReverse / http://localhost: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.
+
  NameVirtualHost *:80
  
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''.
+
<pre>
 +
<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>
  
== Create Editor Group for Restricted Workplace Access ==
+
  ErrorLog logs/errors_www.example.com.log
 +
  CustomLog logs/access_www.example.com.log combined
  
Earlier we created a new site called “/sites/MyNewSite/”. In order to allow the content editors for MyNewSite only edit their own content and not the content under the default site it is possible to create an editor group for MyNewSite and then allow members of this group only access MyNewSite. The steps required to achieve this are listed below:-
+
  RewriteEngine On
 +
  RewriteLog logs/rewrite_www.example.com.log
 +
  RewriteLogLevel 9
  
1) Go to OpenCms account management and create two new groups (e.g. MyNewSiteEditors and MyNewSitePublishers). The editors group must inherit "Users" and publishers group must inherit "None". Leave Group as Role, Project Manager Group and Project Co-Worker unticked for the access group and tick them for the editors group.
+
  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]
  
2) Make sure that you have overwritten permissions for "Users" group for /sites/ to allow nothing.
+
  # If the request starts with /${WEBAPP_NAME}/resources, delete the /${WEBAPP_NAME} prefix
 +
  RewriteCond %{REQUEST_URI}                          ^/opencms/resources/.*$
 +
  RewriteRule ^/opencms/(.*)$                          /$1 [PT]
  
3) Edit permissions for folder “/sites/MyNewSite/” and allow all actions (including inheritance) for groups MyNewSiteEditors and MyNewSitePublishers.
+
  # Also redirect all other 404 errors to OpenCms
 +
  ErrorDocument    404                                /system/shared/handle404.html
  
Now it is possible to create new users for MyNewSite, just by adding the new user to MyNewSiteEditors group (and also to MyNewSitePublishers if they are allowed to publish).
+
  RedirectPermanent /opencms/opencms/                  http://www.example.com/
 +
  ProxyPass        /opencms/opencms/                  !
  
The above access control can be applied also to other resources e.g. image galleries.
+
  ProxyPass        /opencms/resources/                !
 +
  ProxyPass        /opencms/export/                  !
  
'''Please note that above set up defines separate editor and publisher roles. If you want to have single role for everything, you do not need to create the publishers group and just need to make sure that editors group also has publishing rights ticked.'''
+
  ProxyPass        /                                  http://127.0.0.1:8081/opencms/opencms/
 +
  ProxyPassReverse  /                                  http://127.0.0.1:8081/opencms/opencms/
  
 +
</VirtualHost>
 +
</pre>
  
'''OpenCms 7'''
+
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.
  
In OpenCms 7 you can assign a site to a user inside the ''Create/Edit User Dialog'' of the administration.
+
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''.
 
+
[[image:Site_assignment-user_dialog.png]]
+
 
+
== Add New Site to the Search Index ==
+
 
+
In order to enable search functionality for the new site, the site folder must be added to the search index. This can be achieved as described below:-
+
 
+
1) Go to search management and view index sources.
+
 
+
2) Add /sites/MyNewSite/ folder to the resources at "assign resources".
+
 
+
If you have existing pages under /sites/MyNewSite/ you need to touch the pages and republish in order to include them as part of the search index.
+
  
 
[[Category:Getting OpenCms up and running]]
 
[[Category:Getting OpenCms up and running]]

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