Apache 虚拟服务器设置 http 和 https

Apache 虚拟服务器设置 http 和 https

我知道这个问题之前已经被问过几次了但是即使读了几次答案我仍然无法“明白”。

我有一台运行 Apache2 的服务器,我希望能够从中为两个网站提供服务:gitorious.myserver.com 和 redmine.myserver.com。Gitorious 需要 http 和 https(Redmine 只需要 http 就可以了)。

我完全搞不清楚要把什么放在哪里。我尝试编辑 conf.d/redmine.conf、conf.d/gitorious.conf、httpd.conf、sites-available/gitorious 和 sites-available/gitorious-ssl,我不得不承认这一切都很令人困惑。我确实设法让一些东西工作(例如 http 但不是 https),但不是所有的东西都同时工作。我也搞不清楚这些文件之间的区别。

我是否需要对我想要放在 www.myserver.com 子 uri 中的东西做一些特殊的事情(http://www.myserver.com/phpmyadmin或者https://www.myserver.com/someservice例如)?或者只是为这个地址创建一个虚拟服务器,就像为其他地址一样(这是我的理解)。

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>

端口.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>

我不明白 ports.conf 中的注释。

答案1

对于您描述的设置,您需要:

对于其他 Web 应用程序(如上述的 phpMyAdmin),您只需使用别名是 的www.example.com

相关内容