Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I have a website that is http, but has a port set up for https for a specific directory that is for the shopping cart. Now I'd like to use our SSL on a different directory in the same site as well. How can I go about configuring that?

I have tried looking into all of the config files as well as the docs and cannot figure it out.

I tried setting this in httpd.config as well

<VirtualHost 127.0.0.1:[ssl port]>   #also tried *:[ssl port] and [actual IP]:[ssl port]
    ServerAdmin shred@me.com
    DocumentRoot "C:/path/sslNeededDir"
    ServerName www.example.com
</VirtualHost>

hoping that it would cause pages in this directory to use ssl port and become https, but that didn't do anything. Any help is greatly appreciated.

Update: This finally got migrated over. I'm still looking for a solid answer on this. If anyone could help me, it would be greatly appreciated.

share|improve this question
    
What are you using as the ssl port number? –  Pitchinnate May 29 '12 at 21:03
    
The default 443 –  Shredder May 29 '12 at 21:04
3  
Check in conf/extra/httpd-ssl.conf for SSL specific configuration if you are using Apache. When creating an SSL virtual host, there are some special configuration directives that you must set in order for SSL to work. What you have won't actually use SSL. –  drew010 May 29 '12 at 21:10
    
After you made changes did you restart apache? What does your VirtualHost setup for your non-secure section of the site look like? –  Pitchinnate May 29 '12 at 21:10
1  
You will need to either adjust your docroot for the SSL vhost to one that is above both the directories that you want to serve (probably not the best idea) or add an Alias for the other directory you want to serve (better). Whatever you do, you will also need to create/adjust the appropriate <Directory> configurations so that everything you are trying to serve is permitted, and nothing else. –  DaveRandom May 29 '12 at 21:20
show 4 more comments

migrated from stackoverflow.com Jun 7 '12 at 21:55

This question came from our site for professional and enthusiast programmers.

1 Answer

To do this with an alias is probably the simplest method. For argument's sake, lets say that this is your current <VirtualHost> for the directory that is served by SSL (known good config lifted off my dev server, if you're interested):

<VirtualHost 11.22.33.44:443>

  # Basic vhost config
  ServerAdmin administrator@mysite.com
  ServerName secure.mysite.com:443

  # Directory configuration
  DocumentRoot "/WebServer/virtualhosts/secure.mysite.com/htdocs"
  <Directory "/WebServer/virtualhosts/secure.mysite.com/htdocs">
    Options FollowSymLinks ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>

  # Logging configuration
  # Rem: ssl logging format defined in httpd.conf
  ErrorLog "/WebServer/virtualhosts/secure.mysite.com/logs/error.log"
  CustomLog "/WebServer/virtualhosts/secure.mysite.com/logs/access.log" ssl

  # SSL configuration
  # Rem: This works properly, fingerpoken ist verboten!
  SSLEngine on
  SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
  SSLCertificateFile "/var/apache/conf/certs/secure-mysite-com.cert"
  SSLCertificateKeyFile "/var/apache/conf/certs/secure-mysite-com.key"
  <FilesMatch "\.(cgi|shtml|phtml|php)$">
    SSLOptions +StdEnvVars
  </FilesMatch>
  <Directory "/var/apache/cgi-bin">
    SSLOptions +StdEnvVars
  </Directory>
  BrowserMatch ".*MSIE.*" \
    nokeepalive ssl-unclean-shutdown \
    downgrade-1.0 force-response-1.0

</VirtualHost>

As you can (hopefully) see from the above config, when I request the root of the virtual host - i.e. I request https://secure.mysite.com/ - I will be working with the local directory /WebServer/virtualhosts/secure.mysite.com/htdocs.

As you can also hopefully see, setting up a virtual host properly is not just a trivial case of chucking a couple of ServerName and DocumentRoot directives together, it needs to be carefully tuned to do exactly what you want it to. Most of the time you want host-specific logging, if you are using SSL you need to define some basic behaviours and make sure that information is available to your server side scripts, you need to do the obligatory buggering about writing IE specific code and configuration (grrr...) etc etc etc.

Now let's say I want to serve /WebServer/virtualhosts/secure.someothersite.com/htdocs using the same certificate and host name. First I have to decide how I want to be able to access it - and I decide I want to use the address https://secure.mysite.com/someothersite/. I could just create a symlink in the original document root and have done with it, but that would be potentially confusing to other people working with the local file system. No, we'll use the aforementioned Alias directive instead.

The basic syntax for this is Alias /url-path /full/file/system/path - so I will need this line:

Alias /someothersite /WebServer/virtualhosts/secure.someothersite.com/htdocs

Note that I did not include the trailing slash on the end of either of the file paths. This is important for usage to be intuitive and behave as you expect. Great - now Apache will know that when I request /someothersite, I actually want to read a directory that isn't really in the document root. And you might think that's it, job done, but wait...

What about that <Directory> section? That only gives access permissions for the directory defined as DocumentRoot, so we'll need another section for our aliased directory. For the sake of argument, let's just copy/paste the original directory section and change the path it applies to:

<Directory "/WebServer/virtualhosts/secure.someothersite.com/htdocs">
  Options FollowSymLinks ExecCGI
  AllowOverride All
  Order allow,deny
  Allow from all
</Directory>

Now it will work.

Let's have a look at our final configuration:

<VirtualHost 11.22.33.44:443>

  # Basic vhost config
  ServerAdmin administrator@mysite.com
  ServerName secure.mysite.com:443

  # Directory configuration
  DocumentRoot "/WebServer/virtualhosts/secure.mysite.com/htdocs"
  <Directory "/WebServer/virtualhosts/secure.mysite.com/htdocs">
    Options FollowSymLinks ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>

  # Alias for /someothersite virtual directory
  Alias /someothersite /WebServer/virtualhosts/secure.someothersite.com/htdocs
  <Directory "/WebServer/virtualhosts/secure.someothersite.com/htdocs">
    Options FollowSymLinks ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>

  # Logging configuration
  # Rem: ssl logging format defined in httpd.conf
  ErrorLog "/WebServer/virtualhosts/secure.mysite.com/logs/error.log"
  CustomLog "/WebServer/virtualhosts/secure.mysite.com/logs/access.log" ssl

  # SSL configuration
  # Rem: This works properly, fingerpoken ist verboten!
  SSLEngine on
  SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
  SSLCertificateFile "/var/apache/conf/certs/secure-mysite-com.cert"
  SSLCertificateKeyFile "/var/apache/conf/certs/secure-mysite-com.key"
  <FilesMatch "\.(cgi|shtml|phtml|php)$">
    SSLOptions +StdEnvVars
  </FilesMatch>
  <Directory "/var/apache/cgi-bin">
    SSLOptions +StdEnvVars
  </Directory>
  BrowserMatch ".*MSIE.*" \
    nokeepalive ssl-unclean-shutdown \
    downgrade-1.0 force-response-1.0

</VirtualHost>
share|improve this answer
    
I want to set it up for a different directory in the same site. All pages in my cart directory are ssl, now I want to make another directory (in the same site/app root folder) ssl. –  Shredder May 29 '12 at 22:07
    
Well, how do you want to access them? You need some way to determine which directory the files are being requested from. What do your cart directory URLs look like? What do you want your other directories URL's to look like? You can't just have everything as one level URLs (not without a load of rewrite messing around anyway) - what if there are two files with the same name in the different directories? That is why alias is the simplest way, you just access your ither directory under /alias –  DaveRandom May 29 '12 at 22:12
    
My cart URLs are plain: www.shop.com/cart/step1.php - I need to make all pages in the admin folder ssl: www.shop.com/admin/index.php - The cart folder is the only place that is https. I thought there might have been some config for that cart folder and I could just add more config for the admin folder, but I can't find anything like that :/ –  Shredder May 29 '12 at 22:16
    
Are you using <VirtualHost> anywhere currently or not? If you are, can you post the one that currently serves the SSL pages? –  DaveRandom May 29 '12 at 22:19
    
I don't understand because in httpd-ssl.config, it only points to the root (but the root is http; only /cart is https): <VirtualHost _default_:443> DocumentRoot "D:/AppServ/www" ServerName www.site.com:443 - I don't see /cart configured anywhere >_< Thanks for all your help BTW –  Shredder May 29 '12 at 22:20
show 7 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.