Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I know this has been asked a few times before but even after reading the answers a couple of times I still can't "get it".

I have a server running Apache2 and I want to be able to serve two sites from it: gitorious.myserver.com and redmine.myserver.com. Gitorious need both http and https (Redmine is happy with just http).

I'm totally confused on what to put and where. I have tried editing conf.d/redmine.conf, conf.d/gitorious.conf, httpd.conf, sites-available/gitorious and sites-available/gitorious-ssl and I have to admit this all is quite confusing. I do manage to get some stuff to work (e.g. http but not https) but not everything at the same time. I can't figure out the difference between these files either.

And do I need to do something special for stuff that I want to be in a www.myserver.com sub-uri (http://www.myserver.com/phpmyadmin or https://www.myserver.com/someservice for instance)? Or just create a virtual server for this address just as well as for the others (this is how I understand it).

http.conf:

NameVirtualHost *:80
NameVirtualHost *:443

<VirtualHost 192.16.160.65:443>
ServerAdmin poutmar@localhost
DocumentRoot /var/www/gitorious/public
<Directory /var/www/gitorious/public>
        Allow from all
        Options -MultiViews FollowSymLinks
</Directory>
SSLEngine on
SSLCertificateFile    /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
</VirtualHost>

<VirtualHost *:80>
ServerName gitorious.myserver.com
DocumentRoot /var/www/gitorious/public
<Directory /var/www/gitorious/public>
        Allow from all
        Options FollowSymLinks
</Directory>
</VirtualHost>

<VirtualHost *:80>
ServerName redmine.myserver.com
DocumentRoot /var/www/redmine/public
<Directory /var/www/redmine/public>
        Allow from all
        Options -MultiViews FollowSymLinks
</Directory>
</VirtualHost>

<VirtualHost *:80>
ServerName www.myserver.com
DocumentRoot /var/www
<Directory /var/www/>
        Allow from all
        Options FollowSymLinks
</Directory>
</VirtualHost>

<VirtualHost *:443>
ServerName www.myserver.com
DocumentRoot /var/www
<Directory /var/www>
        Allow from all
        Options FollowSymLinks
</Directory>
SSLEngine on
SSLCertificateFile    /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
</VirtualHost>

ports.conf:

Listen 80

<IfModule mod_ssl.c>
    # If you add NameVirtualHost *:443 here, you will also have to change
    # the VirtualHost statement in /etc/apache2/sites-available/default-ssl
    # to <VirtualHost *:443>
    # Server Name Indication for SSL named virtual hosts is currently not
    # supported by MSIE on Windows XP.
    Listen 443
</IfModule>

<IfModule mod_gnutls.c>
    Listen 443
</IfModule>

I don't understand the comment in ports.conf.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

For the setup you've described you'll need:

  • An IP-based VirtualHost on *:443 for gitorious.example.com with SSL/TLS support
  • A name-based VirtualHost on *:80 for gitorious.example.com:
  • A name-based VirtualHost on *:80 for redmine.example.com
  • A name-based VirtualHost on *:80 for example.com and www.example.com (or alternatively just *.example.com).

For other web applications (like the mentioned phpMyAdmin) you can just use Aliases on www.example.com.

share|improve this answer
    
I'm almost there, but I still have a problem with port 443. phpmyadmin also needs ssl, so I configured it so that ww.xx.yy.zz:443 is for Gitorious and *:80 is pointing to the system root but now gitorious.myserver.com goes to the server root rather than gitorious root. I edited my question to include my current definitions. I do get some warning about ssl certificates with wrong CommonName so I need to recreate them later but I assume it should work for now? –  Marko Poutiainen Jul 20 '10 at 6:02
    
Remove NameVirtualHost *:443 and the whole <VirtualHost *:443> block at the end of your httpd.conf. –  joschi Jul 20 '10 at 6:24
    
Login page now works for Gitorious, but it then throws me to the server root. But this might be due to the fact that for some reason Gitorious uses the https protocol for the front page after login (i.e. it opens address gitorious.myserver.com and this ends up opening the "It Works!" page). –  Marko Poutiainen Jul 20 '10 at 8:01

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.