Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Sun Mar 18, 2012 4:39 pm 
Offline
Senior Member

Joined: Wed Jul 21, 2010 8:04 pm
Posts: 119
Hi Everyone,
I run a website off of a Ubuntu server (10.04 LTS, I think) with Apache, MySQL, and PHP. It serves both HTTP and HTTPS content. Currently, I have two main <directory> tags -- one for HTTP and one for HTTPS -- and I'm copying/pasting the same rewrite rules into both of them.

Is there a better way of doing this so I don't have to put the same rewrite rules in twice? Could I create a <directory> tag that would apply to both HTTP and HTTPS and put the rewrite rules in there?

Thanks for your help!

Here's a modified version of my Apache site configuration file (the real one has more rewrite rules):

Code:
<VirtualHost *:80>
   ServerAdmin webmaster@localhost

   DocumentRoot /var/www
   <Directory />
      Options FollowSymLinks
      AllowOverride None
   </Directory>
   <Directory /var/www/>
      Options Indexes FollowSymLinks MultiViews
      AllowOverride None
      Order allow,deny
      allow from all


AddType video/webm .webm

Redirect 301 /pricing-and-signup/ /plans-and-pricing/

RewriteEngine on
RewriteRule ^tryv3/?$ /index.php [L]
RewriteRule ^TRYV3/?$ /index.php [L]

RewriteRule ^404/?$ /Error.php?Error=404 [L]
ErrorDocument 404 /404/


</Directory>

   ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
   <Directory "/usr/lib/cgi-bin">
      AllowOverride None
      Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
      Order allow,deny
      Allow from all
   </Directory>

   ErrorLog /var/log/apache2/error.log

   # Possible values include: debug, info, notice, warn, error, crit,
   # alert, emerg.
   LogLevel warn

   CustomLog /var/log/apache2/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>


<VirtualHost xxx.xxx.xxx.xxx:443>
   ServerAdmin webmaster@localhost
   ServerName [REDACTED]

   SSLEngine On
   SSLCertificateFile [REDACTED]
   SSLCertificateKeyFile [REDACTED]
   SSLCertificateChainFile [REDACTED]

   DocumentRoot /var/www
   <Directory />
      Options FollowSymLinks
      AllowOverride None
   </Directory>
   <Directory /var/www/>
      Options Indexes FollowSymLinks MultiViews
      AllowOverride None
      Order allow,deny
      allow from all


AddType video/webm .webm

Redirect 301 /pricing-and-signup/ /plans-and-pricing/

RewriteEngine on
RewriteRule ^tryv3/?$ /index.php [L]
RewriteRule ^TRYV3/?$ /index.php [L]

RewriteRule ^404/?$ /Error.php?Error=404 [L]
ErrorDocument 404 /404/


</Directory>

   ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
   <Directory "/usr/lib/cgi-bin">
      AllowOverride None
      Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
      Order allow,deny
      Allow from all
   </Directory>

   ErrorLog /var/log/apache2/error.log

   # Possible values include: debug, info, notice, warn, error, crit,
   # alert, emerg.
   LogLevel warn

   CustomLog /var/log/apache2/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

The rewrite rules that are repeated:

Code:
AddType video/webm .webm

Redirect 301 /pricing-and-signup/ /plans-and-pricing/

RewriteEngine on
RewriteRule ^tryv3/?$ /index.php [L]
RewriteRule ^TRYV3/?$ /index.php [L]

RewriteRule ^404/?$ /Error.php?Error=404 [L]
ErrorDocument 404 /404/


Top
   
 Post subject:
PostPosted: Mon Mar 19, 2012 9:39 am 
Offline
Senior Newbie

Joined: Thu May 07, 2009 6:13 am
Posts: 18
Hi jzimmerlin,

As per the Apache 2.2 documentation, http://httpd.apache.org/docs/2.2/mod/co ... irtualhost simply do:

Code:
<VirtualHost 1.2.3.4:80 1.2.3.4:443>
    ...
</VirtualHost>

Regards,


Top
   
 Post subject:
PostPosted: Mon Mar 19, 2012 11:31 am 
Offline
Senior Member

Joined: Wed Jul 21, 2010 8:04 pm
Posts: 119
Thanks, I'll give that a shot!


Top
   
 Post subject:
PostPosted: Fri May 04, 2012 1:03 pm 
Offline
Senior Member

Joined: Wed Jul 21, 2010 8:04 pm
Posts: 119
AlexC wrote:
Hi jzimmerlin,

As per the Apache 2.2 documentation, http://httpd.apache.org/docs/2.2/mod/co ... irtualhost simply do:

Code:
<VirtualHost 1.2.3.4:80 1.2.3.4:443>
    ...
</VirtualHost>

Regards,

OK, so I finally got around to trying this. Unless I misunderstood what you meant, this didn't work.

Code:
<VirtualHost *:80 72.14.190.162:443>
   ServerAdmin webmaster@localhost
   ServerName www.rundowncreator.com

   SSLEngine On
   SSLCertificateFile /etc/apache2/ssl/STAR_rundowncreator_com.crt
   SSLCertificateKeyFile /etc/apache2/ssl/rundowncreator.com.key
   SSLCertificateChainFile /etc/apache2/ssl/PositiveSSL.ca-bundle

   DocumentRoot /var/www
   <Directory />
      Options FollowSymLinks
      AllowOverride None

(REWRITE RULES WOULD GO HERE)

   </Directory>
   <Directory /var/www/>
      Options Indexes FollowSymLinks MultiViews
      AllowOverride None
      Order allow,deny
      allow from all
   </Directory>

   ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
   <Directory "/usr/lib/cgi-bin">
      AllowOverride None
      Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
      Order allow,deny
      Allow from all
   </Directory>

   ErrorLog /var/log/apache2/error.log

   # Possible values include: debug, info, notice, warn, error, crit,
   # alert, emerg.
   LogLevel warn

   CustomLog /var/log/apache2/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

...will force SSL on port 80 and 443, which is not what I want. And...

Code:
<VirtualHost *:80 72.14.190.162:443>
   ServerAdmin webmaster@localhost

   DocumentRoot /var/www
   <Directory />
      Options FollowSymLinks
      AllowOverride None

(REWRITE RULES WOULD GO HERE)

   </Directory>
   <Directory /var/www/>
      Options Indexes FollowSymLinks MultiViews
      AllowOverride None
      Order allow,deny
      allow from all
   </Directory>

   ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
   <Directory "/usr/lib/cgi-bin">
      AllowOverride None
      Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
      Order allow,deny
      Allow from all
   </Directory>

   ErrorLog /var/log/apache2/error.log

   # Possible values include: debug, info, notice, warn, error, crit,
   # alert, emerg.
   LogLevel warn

   CustomLog /var/log/apache2/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

<VirtualHost 72.14.190.162:443>
        ServerAdmin webmaster@localhost
        ServerName www.rundowncreator.com

        SSLEngine On
        SSLCertificateFile /etc/apache2/ssl/STAR_rundowncreator_com.crt
        SSLCertificateKeyFile /etc/apache2/ssl/rundowncreator.com.key
        SSLCertificateChainFile /etc/apache2/ssl/PositiveSSL.ca-bundle
</VirtualHost>

...gives me:

Code:
[Fri May 04 10:00:31 2012] [warn] VirtualHost 72.14.190.162:443 overlaps with VirtualHost 72.14.190.162:443, the first has precedence, perhaps you need a NameVirtualHost directive

Any ideas?


Top
   
PostPosted: Thu Jun 14, 2012 1:24 am 
Offline
Junior Member

Joined: Thu Jul 19, 2007 5:30 am
Posts: 28
You may have more success putting the common configuration in a third file, and including that file from each vhost. The warning message is telling you to add a NameVirtualHost directive. If that doesn't do it, I wouldn't be sure how to mix non-secured and secured vhost definitions either.


Top
   
PostPosted: Thu Jul 19, 2012 4:47 pm 
Offline
Senior Member

Joined: Wed Jul 21, 2010 8:04 pm
Posts: 119
How would you include the file?


Top
   
PostPosted: Thu Jul 19, 2012 5:57 pm 
Offline
Junior Member

Joined: Thu Jul 19, 2007 5:30 am
Posts: 28
http://httpd.apache.org/docs/2.2/mod/core.html#include should do it.


Top
   
PostPosted: Thu Jul 19, 2012 5:59 pm 
Offline
Senior Member

Joined: Wed Jul 21, 2010 8:04 pm
Posts: 119
I'll give that a shot, thanks!


Top
   
PostPosted: Thu Jul 19, 2012 9:27 pm 
Offline
Senior Member

Joined: Wed Jul 21, 2010 8:04 pm
Posts: 119
It worked. Thank you!


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group