Apache Virtual Host

  • PolishHurricane
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1585

Post 3+ Months Ago

I just setup SSL on an apache server and I have a some virtual hosts that look like this...

Code: [ Select ]
NameVirtualHost *:80
NameVirtualHost *:443

<VirtualHost *:80>
#followed by more stuff...
</VirtualHost>

<VirtualHost *:443>
SSLEngine On
SSLCertificateFile conf/ssl/server.crt
SSLCertificateKeyFile conf/ssl/server.key

#followed by more stuff...
</VirtualHost>
  1. NameVirtualHost *:80
  2. NameVirtualHost *:443
  3. <VirtualHost *:80>
  4. #followed by more stuff...
  5. </VirtualHost>
  6. <VirtualHost *:443>
  7. SSLEngine On
  8. SSLCertificateFile conf/ssl/server.crt
  9. SSLCertificateKeyFile conf/ssl/server.key
  10. #followed by more stuff...
  11. </VirtualHost>


But I wish to combine them. Is there anyway I can do something like this?

Code: [ Select ]
<VirtualHost *:80 *:443>
if(VirtualHost *:443)
{
SSLEngine On
SSLCertificateFile conf/ssl/server.crt
SSLCertificateKeyFile conf/ssl/server.key
}

#followed by more stuff...
</VirtualHost>
  1. <VirtualHost *:80 *:443>
  2. if(VirtualHost *:443)
  3. {
  4. SSLEngine On
  5. SSLCertificateFile conf/ssl/server.crt
  6. SSLCertificateKeyFile conf/ssl/server.key
  7. }
  8. #followed by more stuff...
  9. </VirtualHost>


I don't get how to say IF using port 443, enable SSL. I wish to do this because there is a lot of stuff written between the virtual host tags and I do not wish to repeat it twice everytime I wish to change something in the configuration.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

What about this ?
Code: [ Select ]
<VirtualHost 255.255.255.255:80 255.255.255.255:443>
# stuff...
</VirtualHost>

<VirtualHost 255.255.255.255:443>
SSLEngine On
SSLCertificateFile conf/ssl/server.crt
SSLCertificateKeyFile conf/ssl/server.key
</VirtualHost>
  1. <VirtualHost 255.255.255.255:80 255.255.255.255:443>
  2. # stuff...
  3. </VirtualHost>
  4. <VirtualHost 255.255.255.255:443>
  5. SSLEngine On
  6. SSLCertificateFile conf/ssl/server.crt
  7. SSLCertificateKeyFile conf/ssl/server.key
  8. </VirtualHost>


http://httpd.apache.org/docs/2.2/vhosts/examples.html
  • PolishHurricane
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1585

Post 3+ Months Ago

hmmm... This is what I have now that works. The problem is, I had to copy and paste the settings from <VirtualHost *:80> into the ssl.conf file because everyone was able to see my "Websites" folder, when I only wanted them to see the "PublicWebsite" folder. But I don't want to have to declare directory permissions in my ssl.conf folder... that doesn't seem like I should need to. And everytime I change something in <VirtualHost *:80> I need to change it in <VirtualHost _default_:443>.

Oh and I'm not even sure which NameVirtualHost things I need. I declared it 4 times, lol...

And "SSL Mutex sem" doesn't work, or any Mutex for that matter when I try to start the server with SSL, the server works without it. But from what I've read it's good to have it.

This is the ssl.conf file:
Code: [ Select ]
<VirtualHost _default_:443>
DocumentRoot "C:/Path/To/Websites/PublicWebsite"
#the same exact document root and directory settings as *:80
#A TON TON TON of SSL stuff including (not next to each other though)...
SSLEngine On
SSLCertificateFile conf/ssl/server.crt
SSLCertificateKeyFile conf/ssl/server.key
</VirtualHost>
  1. <VirtualHost _default_:443>
  2. DocumentRoot "C:/Path/To/Websites/PublicWebsite"
  3. #the same exact document root and directory settings as *:80
  4. #A TON TON TON of SSL stuff including (not next to each other though)...
  5. SSLEngine On
  6. SSLCertificateFile conf/ssl/server.crt
  7. SSLCertificateKeyFile conf/ssl/server.key
  8. </VirtualHost>


This is the httpd.conf file:
Code: [ Select ]
#a bunch of stuff up here ^
Include conf/ssl.conf

<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>

#SSL Mutex sem
SSLMutex default
SSLRandomSeed startup builtin
SSLSessionCache none

ErrorLog logs/ssl.log
LogLevel info

NameVirtualHost 127.0.0.1:80
NameVirtualHost 127.0.0.1:443
NameVirtualHost *:80
NameVirtualHost *:443

#localhost
<VirtualHost 127.0.0.1:80 127.0.0.1:443>
DocumentRoot "C:/Path/To/Websites"
#some directory permissions for localhost so I can see more directories
</VirtualHost>

#Public Port 80
<VirtualHost *:80>
DocumentRoot "C:/Path/To/Websites/PublicWebsite"
#document root and more restrictive public directory permissions for port 80
</VirtualHost>
  1. #a bunch of stuff up here ^
  2. Include conf/ssl.conf
  3. <IfModule ssl_module>
  4. SSLRandomSeed startup builtin
  5. SSLRandomSeed connect builtin
  6. </IfModule>
  7. #SSL Mutex sem
  8. SSLMutex default
  9. SSLRandomSeed startup builtin
  10. SSLSessionCache none
  11. ErrorLog logs/ssl.log
  12. LogLevel info
  13. NameVirtualHost 127.0.0.1:80
  14. NameVirtualHost 127.0.0.1:443
  15. NameVirtualHost *:80
  16. NameVirtualHost *:443
  17. #localhost
  18. <VirtualHost 127.0.0.1:80 127.0.0.1:443>
  19. DocumentRoot "C:/Path/To/Websites"
  20. #some directory permissions for localhost so I can see more directories
  21. </VirtualHost>
  22. #Public Port 80
  23. <VirtualHost *:80>
  24. DocumentRoot "C:/Path/To/Websites/PublicWebsite"
  25. #document root and more restrictive public directory permissions for port 80
  26. </VirtualHost>

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 13 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.