LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 01-17-2013, 10:27 AM   #1
bkone
Member
 
Registered: Jun 2006
Distribution: SUSE, Red Hat, Oracle Linux, CentOS
Posts: 108

Rep: Reputation: 15
apache2 virtualhost same URL different location


I have a site which I am trying to have go to different file locations. Here is my example:
The site name is development.mysite.com if that is keyed into the address bar of the browser then goto this directory /srv/www/htdocs.mysite1 if development.mysite.com/newstuff gets keyed into the browser then goto this directory /srv/www/htdocs.newstuff.

I'm also using SSL so I am redirecting the sites from http to https which all works but I can get the two sites working.
Here is my config:
Code:
<VirtualHost *:80>
 ServerName development.mysite.com
 Alias /newstuff /srv/www/htdocs.newstuff
 DocumentRoot /srv/www/htdocs.newstuff
 DirectoryIndex index.php

 ErrorLog /var/log/apache2/newstuff-error_log
 CustomLog /var/log/apache2/newstuff-access_log combined

 <Directory "/srv/www/htdocs.newstuff">
  Options -Indexes FollowSymLinks
  AllowOverride All
  CheckSpelling on
  Order allow,deny
  Allow from all
 </Directory>

 RewriteEngine On
 RewriteCond %{HTTPS} off
 RewriteRule ^(.*) https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
</VirtualHost>
<VirtualHost *:80>
 ServerName development.mysite.com
 Alias / /srv/www/htdocs.mysite1
 DocumentRoot /srv/www/htdocs.mysite1
 DirectoryIndex index.php

 ErrorLog /var/log/apache2/mysite1-error_log
 CustomLog /var/log/apache2/mysite1-access_log combined

 <Directory "/srv/www/htdocs.mysite1">
  Options Indexes FollowSymLinks
  AllowOverride None
  Order allow,deny
  Allow from all
  CheckSpelling on
 </Directory>

 RewriteEngine On
 RewriteCond %{HTTPS} off
 RewriteRule ^(.*) https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
</VirtualHost>
Here is my SSL conf file as well:
Code:
<VirtualHost *:443>
 ServerName development.mysite.com
 Alias /newstuff /srv/www/htdocs.newstuff
 DocumentRoot /srv/www/htdocs.newstuff
 DirectoryIndex index.php

 #RewriteEngine off
 #RewriteCond %{REQUEST_METHOD} ^TRACE
 #RewriteRule .* - [F]

 ErrorLog /var/log/apache2/newstuff-error_log
 CustomLog /var/log/apache2/newstuff-access_log combined

 <Directory "/srv/www/htdocs.newstuff">
  Options -Indexes FollowSymLinks
  AllowOverride None
  CheckSpelling on
  Order allow,deny
  Allow from all
 </Directory>

 SSLEngine on
 SSLProtocol -ALL +SSLv3 +TLSv1
 SSLCipherSuite ALL:!aNULL:!eNULL:!SSLv2:!LOW:!EXP:!MD5:@STRENGTH
 SSLCertificateFile /etc/apache2/ssl.crt/newstuff.cer
 SSLCertificateChainFile /etc/apache2/ssl.crt/newstuff.p7b
 SSLCertificateKeyFile /etc/apache2/ssl.key/newstuff.key

 <Files ~ "\.(cgi|shtml|phtml|php3?)$">
  SSLOptions +StdEnvVars
 </Files>
 <Directory "/srv/www/cgi-bin">
  SSLOptions +StdEnvVars
 </Directory>

   RewriteEngine on
   RewriteRule ^[\w:/\%]*(\.(?!(js|ico|gif|jpg|png|css|htm|asp|pdf|swf|fla|doc|pps|ppt|class|jar|mp3))[\w\%\.]*)?$ /atrac/index.php
   RewriteLog /var/log/apache2/newstuffev-rewrite.log
   RewriteLogLevel 4
</VirtualHost>

<VirtualHost *:443>
 ServerName development.mysite.com
 Alias / /srv/www/htdocs.mysite1
 DocumentRoot /srv/www/htdocs.mysite1
 DirectoryIndex index.php

 RewriteEngine on
 RewriteCond %{REQUEST_METHOD} ^TRACE
 RewriteRule .* - [F]

 ErrorLog /var/log/apache2/mysite1-error_log
 CustomLog /var/log/apache2/mysite1-access_log combined

 <Directory "/srv/www/htdocs.mysite1">
  Options -Indexes FollowSymLinks
  AllowOverride None
  CheckSpelling on
  Order allow,deny
  Allow from all
 </Directory>

 SSLEngine on
 SSLProtocol -ALL +SSLv3 +TLSv1
 SSLCipherSuite ALL:!aNULL:!eNULL:!SSLv2:!LOW:!EXP:!MD5:@STRENGTH
 SSLCertificateFile /etc/apache2/ssl.crt/mysite1.cer
 SSLCertificateChainFile /etc/apache2/ssl.crt/mysite1.p7b
 SSLCertificateKeyFile /etc/apache2/ssl.key/mysite1.key

 <Files ~ "\.(cgi|shtml|phtml|php3?)$">
  SSLOptions +StdEnvVars
 </Files>
 <Directory "/srv/www/cgi-bin">
  SSLOptions +StdEnvVars
 </Directory>
</VirtualHost>

</IfDefine>
The development.mysite.com always goes to the /srv/www/htdocs.newstuff directory. I can't figure out how to get it to goto the /srv/www/htdocs.mysite1 location for that index.php file.
 
Old 01-17-2013, 10:35 AM   #2
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
You need to set your alias correctly.

So set:

Code:
Alias /newstuff /srv/www/htdocs.newstuff
This alias should be set inside of your virtual host for /srv/www/htdocs.mysite1 you do not need a virtual host for your newstuff.

All you are doing is telling Apache taht when you request that folder path /newstuff on the domain that the vhost is setup for to pull the content for the folder specified.

Your aliases with / are not really doing much doesnt look like.
 
Old 01-17-2013, 11:15 AM   #3
bkone
Member
 
Registered: Jun 2006
Distribution: SUSE, Red Hat, Oracle Linux, CentOS
Posts: 108

Original Poster
Rep: Reputation: 15
The problem I am seeing is that when I access development.mysite.com the browser, apache, is pulling the pages from the /srv/www/htdocs.newstuff and not /srv/www/htdocs.mysite1. If I use development.mysite.com/newstuff it uses the content in /srv/www/htdocs.newstuff but using development.mysite.com also uses the newstuff content and not the /srv/www/htdocs.mysite1 content.
 
Old 01-17-2013, 11:19 AM   #4
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
Thats because you have it explictly set in as your document root in your virtual host. Change the document root for your vhost to be the actual directory you want the content to come from.
 
Old 01-17-2013, 12:17 PM   #5
bkone
Member
 
Registered: Jun 2006
Distribution: SUSE, Red Hat, Oracle Linux, CentOS
Posts: 108

Original Poster
Rep: Reputation: 15
I am not following you.

My one site is this:
Code:
ServerName development.mysite.com
 Alias /newstuff /srv/www/htdocs.newstuff
 DocumentRoot /srv/www/htdocs.newstuff
 DirectoryIndex index.php
The other is this:
Code:
ServerName development.mysite.com
 DocumentRoot /srv/www/htdocs.mysite1
 DirectoryIndex index.php
What are you thinking I need to change?
 
Old 01-17-2013, 12:19 PM   #6
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
Code:
ServerName development.mysite.com
 Alias /newstuff /srv/www/htdocs.newstuff
 DocumentRoot /srv/www/htdocs.newstuff
 DirectoryIndex index.php
To

Code:
ServerName development.mysite.com
 Alias /newstuff /srv/www/htdocs.newstuff
 DocumentRoot /srv/www/htdocs.mysite1
 DirectoryIndex index.php
 
Old 01-17-2013, 12:20 PM   #7
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
Compeletely remove the first vhost entry for the /newstuff folder. You do not need a virtual host record for a subdirectory on the same server name!

If it was a different subdomain or domain you would need two vhosts, you only need one vhost for port 80 and one for port 443
 
Old 01-21-2013, 10:52 AM   #8
bkone
Member
 
Registered: Jun 2006
Distribution: SUSE, Red Hat, Oracle Linux, CentOS
Posts: 108

Original Poster
Rep: Reputation: 15
Well, that appears to work somewhat. Not sure what else I am missing but I placed all the content into one directory. Moved all of /srv/www/htdocs.newstuff into /srv/www/htdocs.mysite1 and it works. Not sure why I cannot use a different directory like I was /srv/www/htdocs.newstuff but I would just get a 403 error Access Forbidden and from what I can tell signifies a missing index page? Not sure. Can I specify both directories in the Directory portion?

<Directory "/srv/www/htdocs.newstuff">
Directory "/srv/www/htdocs.mysite1"
Options -Indexes FollowSymLinks
AllowOverride All
CheckSpelling on
Order allow,deny
Allow from all
</Directory>

Then I have the complexity of SSL certs which I have created using an internal certificate authority. Do I create two seperate entries in teh ssl-vhost.conf file or combine them again like I did in the vhost.conf file?

I am in unchartered waters.
 
Old 01-22-2013, 12:58 PM   #9
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
You can use as many Directory 'directives' as possible, however, they all must be separate! You can have multiple <Directory> directives within a <VirtualHost> directive. So:

Code:
<VirtualHost *:80>
Directives
      <Directory 1>
       Directives
      </Directory 1>
      <Directory 2>
       Directives
      </Directory 2>
</VirtualHost>

The 403 error can be caused by many things.

The one thing to remember about Apache is that it is designed as a restrictive server. Meaning that it will not serve content unless explicitly told to do so, this is why you will always see the Allow from all directives.

When receiving any apache error check your /var/log/httpd/error.log file as it will give you the exact cause.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache2 virtualhost setup shorto Linux - Server 5 02-09-2012 01:12 AM
Apache2 VirtualHost's NOT working randomblink Linux - Server 1 09-21-2008 01:35 AM
Apache2 VirtualHost Question martinyeh Linux - Server 18 06-01-2008 03:25 PM
Apache2 VirtualHost and SSL Alfar Linux - Server 2 10-20-2007 01:10 AM
Using VirtualHost with single IP in Apache2 gurl4sh25 Linux - Server 2 05-06-2007 09:32 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 12:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration