简体   繁体   中英

How to run multiple SSL enabled websites for local development using Apache

I have a couple websites I'm developing and through virtual servers and different document roots, have them configured to be accessed based on port. Ie localhost:8010 for one site, localhost:8020 for another.

Before I had multiple sites, SSL worked fine with just one using ports 80 and 443. However now the unescured sites load fine but for either one the SSL connection cannot be established. It also seems like its not changing the port--when I click on a link that starts with https:// it tries to go to https://localhost:8010/secure/route .

I'm fine with either urls like https://localhost:8010/secure/route to work, or for it depending on the site to auto-escalate to some other port (ie https://localhost:8011/project/one/secure/route , https://localhost:8021/project/two/secure/route ), or something else as long as I can run two sites locally using different ports and SSL!

In my httpd.conf I have:

Listen 8010
Listen 8020

as well as:

<Directory "/path/to/project/one">
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Require all granted
</Directory>

<Directory "/path/to/project/two">
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Require all granted
</Directory>

In my httpd-vhosts.conf I have:

<VirtualHost *:8010>
    ServerAdmin zugwalt@projectone.com
    DocumentRoot "/path/to/project/one"
    ServerName localhost:8010
    ErrorLog "logs/projectone-error.log"
    CustomLog "logs/projectone-access.log" common
</VirtualHost>

<VirtualHost *:8020>
    ServerAdmin zugwalt@projecttwo.com
    DocumentRoot "/path/to/project/two"
    ServerName localhost:8020
    ErrorLog "logs/projecttwo-error.log"
    CustomLog "logs/projecttwo-access.log" common
</VirtualHost>

And in my httpd-ssl.conf I have:

Listen 443

<VirtualHost *:443>
    DocumentRoot "/path/to/project/one"
    ServerName localhost:8010
    SSLEngine on
    SSLCertificateFile /path/to/ssl/server.crt
    SSLCertificateKeyFile /path/to/ssl/server.key
</VirtualHost>

<VirtualHost *:443>
    DocumentRoot "/path/to/project/two"
    ServerName localhost:8020
    SSLEngine on
    SSLCertificateFile /path/to/ssl/server.crt
    SSLCertificateKeyFile /path/to/ssl/server.key
</VirtualHost>

I'm using Apache 2.4 on Windows 7

You defined both virtual host to be on Port 443 <VirtualHost *:443> but you have no real dns hostname for each one! You set the servernames to localhost:8010 and 8020 - this will not work, because the port is not part of the dns name!

You must have different servernames like ssl1.example.com and ssl2.example.com - on the other hand you could define different ports for ssl like you did for pure http:

<VirtualHost *:8110>
  DocumentRoot "/path/to/project/one"
  ServerName localhost
  SSLEngine on
  SSLCertificateFile /path/to/ssl/server.crt
  SSLCertificateKeyFile /path/to/ssl/server.key
</VirtualHost>

<VirtualHost *:8120>
  DocumentRoot "/path/to/project/two"
  ServerName localhost
  SSLEngine on
  SSLCertificateFile /path/to/ssl/server.crt
  SSLCertificateKeyFile /path/to/ssl/server.key
</VirtualHost>

Then use the port within your browser:

https://localhost:8110

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM