How to correctly set Documentroot in Apache serving Plone - apache

I have a Plone site called example.com located at /var/www/Plone (I think). I have the following settings for the site located in sites-available for vhosts (excerpt):
<VirtualHost 10.0.1.4:8082>
ServerAdmin webmaster#localhost
ServerName wiedhas.noip.me
DocumentRoot /var/www/Plone
When I try to reach my site wiedhas.noip.me, apache loads the Plone directory tree and not my Plone site. I can browse through the file system of /var/www/Plone but it is not loading the site. I must not have set the documentroot to the correct directory of my site? Any help much appreciated.

This an excellent docu about running plone behind apache and more.
http://docs.plone.org/manage/deploying/front-end/apache.html
A simple example with ssl, how a vhost could look like:
<VirtualHost $IP:80>
ServerName my.domain.com
Redirect / https://my.domain.com
</VirtualHost>
<VirtualHost $IP:443>
ServerName my.domain.com
ErrorLog logs/my.domain.com-http-error.log
CustomLog logs/my.domain.com-http-access.log combined
Include vhosts.d/....ssl.inc
RewriteEngine On
RewriteRule ^/(.*) http://127.0.0.1:$PORT_OF_PLONE/VirtualHostBase/https/%{SERVER_NAME}:%{SERVER_PORT}/zodb/path/top/plone/VirtualHostRoot/$1 [P,L]
</VirtualHost>
The most important part is the rewrite rule:
RewriteRule ^/(.*) http://127.0.0.1:$PORT_OF_PLONE/VirtualHostBase/https/%{SERVER_NAME}:%{SERVER_PORT}/zodb/path/top/plone/VirtualHostRoot/$1 [P,L]
$PORT_OF_PLONE = Port of your running plone instance
/zodb/path/top/plone = That's where you added the plone site in zope.

Took me a while to get mine going so maybe this helps:
My vhosts looks like this (where my plone site is called 'mywebsite'):
#---------------------------------
# www.mywebsite.com
#---------------------------------
<VirtualHost *:80>
ServerName www.mywebsite.com
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^/(.*)$ http://127.0.0.1:8081/VirtualHostBase/http/%{SERVER_NAME}:80/mywebsite/VirtualHostRoot/$1 [L,P]
</IfModule>
</VirtualHost>
Hope that helps :)

As you see in the first and correct answer you do not need DocumentRoot. DocumentRoot points to a directory with files to render by Apache. But Plone brings it's own server, the Zope application server, which runs on a different port than Apache. The RewriteRule redirects the incoming request to the application server and modifies the response in a way that the redirection is hidden for the client.

Related

Rewrite Rule Causing too many redirects

I am hosting multiple sites on Apache.
Wordpress configuration works perfectly, however configuring moodle site is causing too many redirects. This is my configuration in httpds-ssl.conf, please help.
#Word press config works perfectly
DocumentRoot "c:/Apache24/htdocs/wp"
ServerName http://uat.dummy.com.au:443
#Moodle causing too many redirects
<VirtualHost *:443>
ServerName uatlms.dummy.com.au
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/moodle/
RedirectMatch ^/$ /moodle [L,R=301]
</VirtualHost>
I need moodle to be appended to URL, so the end result should be uatlms.dummy.com.au/moodle (that's why can't do DocumentRoot option)
You mentioned a moodle site - if all requests to the site are to go to "/moodle", it is best to set DocumentRoot accordingly:
<VirtualHost *:443>
ServerName uatlms.dummy.com.au
DocumentRoot "c:/Apache24/htdocs/moodle"
</VirtualHost>

Apache proxypass - show local file if exist

i use apache proxypass to show content from other server to my base server
i use this code
<VirtualHost *:80>
ServerAdmin webmaster#example.com
DocumentRoot /var/www/html/2
ServerName 2.example.com
ProxyPass /tv http://t1.example.com/tv/
ProxyPassReverse /tv http://t1.example.com/tv/
ErrorLog logs/errorlive_log
CustomLog logs/access_live common
</VirtualHost>
so is there a way first to check if file exist on 2.example.com (/var/www/html/2) if file exist show from this server and if file dont exist then request and server from t1.example.com/tv/
-and i have second question:
if server2 serve a video which is located in server1 and on server 2 are watching 10 users (10mbps) , so from which server will be taken 10mbps from server 2 or server 1 or both servers will have 10mbps load
In apache doc,you can see Ordering ProxyPass and RewriteRule Directives
RewriteRule directives are evaluated before ProxyPass ones.
So, you can add a rewrite rule which test if file exist
<VirtualHost *:80>
ServerAdmin webmaster#example.com
DocumentRoot /var/www/html/2
ServerName 2.example.com
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .* - [L]
ProxyPass /tv http://t1.example.com/tv/
ProxyPassReverse /tv http://t1.example.com/tv/
ErrorLog logs/errorlive_log
CustomLog logs/access_live common
</VirtualHost>
RewiteCond test if %{REQUEST_FILENAME} is a regular file and then rewriteRule rewrites to the file. It can be a html, image, php file, etc ...
Now, you can adapt to your need.
EDIT
For second question, I forgot to answer. Sorry, my bad.
According to Apache mod_proxy documentation :
"A reverse proxy (or gateway), by contrast, appears to the client just like an ordinary web server. No special configuration on the client is necessary. The client makes ordinary requests for content in the namespace of the reverse proxy. The reverse proxy then decides where to send those requests and returns the content as if it were itself the origin."
So, both server are loaded.

Apache SSL config breaks HTTP

I have installed an SSL certificate today, and it works perfectly, pages sought through https:// work fine.
I have put a redirect in my website.conf to redirect port 80 to https, but it is not working.
Also if I go to http://www.example.org (the root), it gets stuck in a redirect loop.
going to http://www.example.org/test.htm goes to the same url minus the last /. eg http://www.example.orgtest.htm/ (slash moves to end)
This is really busting my balls, i really hope you guys have some clues.
here is my .conf file
NameVirtualHost *:80
<VirtualHost *:80>
ServerName example.org
Redirect permanent / https://www.example.org
</VirtualHost>
<VirtualHost _default_:443>
# Admin email, Server Name (domain name), and any aliases
ServerAdmin richard#example.org
ServerName example.org
ServerAlias www.example.org
# Index file and Document Root (where the public files are located)
DirectoryIndex index.html index.org
DocumentRoot /var/www/example.org/html
# SSL settings
SSLEngine on
SSLCertificateFile /etc/ssl/certs/www_example_org.crt
SSLCertificateKeyFile /etc/ssl/digicert/example.key
SSLCACertificateFile /etc/ssl/certs/DigiCertCA.crt
# Log file locations
LogLevel warn
ErrorLog /var/www/example.org/log/error.log
CustomLog /var/www/example.org/log/access.log combined
</VirtualHost>
Your config looks fine for me. Maybe, you should append a / like this: Redirect permanent / https://www.example.org/
Instead of using Redirect permanent, you could also use mod_rewrite:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
For this to work, you must have installed the mod_rewrite module.
If you would like for force https, another approach is so set the HSTS-Header in your Apache config. Then, a browser knows that your website is available with https and will automatically redirect all traffic to your https-address. You can set this header with the following command:
Header always set Strict-Transport-Security "max-age=63072000; includeSubdomains; preload"
In general, I would recommend reviewing your SSL-config with SSLLabs. If your config is fine, you should get an A+-Rating. I hope this helps.
well i worked it out after much tears, i was missing
ServerAlias www.example.org
for port 80, Thanks to Ben for the HSTS header though, i will def use that. cheers

Apache Settings For Unique subdomain and Domain Directories

I'm fairly capable with most of the web server configuration but I have run into a problem.
I have a VPS install with one sub domain. Currently the link sub1.domain.com points to the root of the public_html/www folder.
I am now looking at creating new sub domains as well as using domain.com to point to a wordpress installation.
From my understanding, I must edit the apache httpd.conf file, but I am unsure exactly how to do this. I would expect that I would have to have domain.com point to a subdirectory as well as sub2.domain.com point to a different sub directory. Something like the following.
sub1.domain.com >> rootPathForApache/
domain.com >> rootPathForApache/domain.com/
sub2domain.com >> rootPathForApache/sub2/
Could somebody please point me in the right direction.
Kind Regards,
You have a couple options:
Option 1: Apache's <VirtualHost> directive could solve this (multiple). This is only available in the server config context.
<VirtualHost *:80>
DocumentRoot "rootPathForApache/"
ServerName sub1.domain.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "rootPathForApache/domain.com/"
ServerName domain.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "rootPathForApache/sub2/"
ServerName sub2domain.com
</VirtualHost>
Option 2: Use a .htaccess file in rootPathForApache with the mod_rewrite module loaded, and introduce ServerAlias directive into either your existing <VirtualHost> directive.
.htaccess contents (or if you want within the VirtualHost directive itself):
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub1.domain.com
RewriteRule ^(.*) $1 [L]
RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule ^(.*) domain.com/$1 [L]
RewriteCond %{HTTP_HOST} ^sub2domain.com
RewriteRule ^(.*) sub2/$1 [L]
...and the ServerAlias:
ServerName domain.com
ServerAlias sub1.domain.com sub2domain.com
The latter solution (option 2) just seems ridiculous, especially since ServerAlias is only available within a VirtualHost directive and mod_rewritehtaccess files add unnecessary overhead. That and it doesn't seem natural. I guess it illustrates the flexibility of Apache's configuration and modules.

How to do an Apache HTTP server virtual host blanket redirect with exceptions

I am running an Apache HTTP server that accepts requests for my domain. Lets call it www.mydomain.com. I have several sites that run under this domain and I have virtual hosts set up for each one that forwards the user depending upon with URL they use. Examples would be a.mydomain.com, b.mydomain.com, etc. I am aware that this may not have been the best way to accomplish this goal considering there are over 100 virtual hosts, but it is something I have inhertited and.. to put it short.. it works. Now on to my problem.
I have recently been tasked with shutting down most of the sites running under the domain. The sites that are shut down have been redirected to one page on my new domain (www.mynewdomain.com). What I have done is changed each of the virtual hosts from something like this:
<VirtualHost *:80>
ServerName a.mydomain.com
RewriteEngine On
RewriteRule ^/$ /SiteA [PT]
</VirtualHost>
to this:
<VirtualHost *:80>
ServerName a.mydomain.com
Redirect permanent / http://www.mynewdomain.com/replacement
</VirtualHost>
So now I have a list of 100 hosts that all redirect to the same place. What I need to know is if there exists a way to tell the system to redirect all sites at *.mydomain.com to my new page except certain ones. So some entry like this:
<VirtualHost *:80>
ServerName *.mydomain.com
Redirect permanent / http://www.mynewdomain.com/replacement
</VirtualHost>
<VirtualHost *:80>
ServerName h.mydomain.com
RewriteEngine On
RewriteRule ^/$ /SiteH [PT]
</VirtualHost>
<VirtualHost *:80>
ServerName v.mydomain.com
RewriteEngine On
RewriteRule ^/$ /SiteV [PT]
</VirtualHost>
Which means that every URL you see will go to "http://www.mynewdomain.com/replacement" except "h.mydomain.com" and "v.mydomain.com". The virtual hosts for "h" and "v" must still be intact because I have RewriteRules for each that must continue to work (additional rewriterules not seen in my examples).
Thanks in advance for the assistance!