cmdref.net - Cheat Sheet and Example

cmdref.net is command references/cheat sheets/examples for system engineers.

User Tools

Site Tools


Sidebar








Etc


Reference














.

middleware:web:httpd:virtualhosts.html



Apache HTTP Server Configuration Examples

Apache HTTPD :: Virtual Host

How to create a virtual host

Name Based Virtual Host

example.com  192.168.0.11
test.com     192.168.0.11

IP Based Virtual Host

example.com  192.168.0.11
test.com     192.168.0.12


Sample Configuration

How to create a virtual host that works with both http and https?

Listen 443
Listen 80
NameVirtualHost *:80
NameVirtualHost *:443
ServerName *:80


<virtualhost *:80 *:443>
  ServerName example.com
  DocumentRoot /var/www/example.com
</virtualhost>

<virtualhost *:80 *:443>
  ServerName test.com
  DocumentRoot /var/www/test.com
</virtualhost>

SSL

NameVirtualHost *:443

<VirtualHost *:443>
  DocumentRoot    /var/www/html/example
  ServerName      www.exammple:443
  SSLEngine on
  SSLCertificateChainFile /etc/httpd/conf/chain.cer
  SSLCertificateFile "/etc/httpd/conf/www.crt"
  SSLCertificateKeyFile "/etc/httpd/conf/www.key"
  ErrorLog /var/log/httpd/error_log
  TransferLog /var/log/httpd/access_log
</VirtualHost>

IP Based

Listen 80

BindAddress 192.168.0.11 192.168.0.12

<VirtualHost 192.168.0.11>
    ServerName www.sample1.com
    DocumentRoot /var/www/sample1
    ErrorLog logs/sample1_error_log
    TransferLog logs/sample1_access_log
</VirtualHost>

<VirtualHost 192.168.0.12>
    ServerName www.sample2.com
    DocumentRoot /var/www/sample2
    ErrorLog logs/sample2_error_log
    TransferLog logs/sample2_access_log
</VirtualHost>



middleware/web/httpd/virtualhosts.html.txt ยท Last modified: 2018/12/22 by admin

Page Tools