Skip to main content

Apache/NGINX vhost's

Apache vhost

vim /etc/httpd/conf/httpd.conf

add << include vhosts/*.conf >> at the bottom

mkdir /etc/httpd/vhosts

vim /etc/httpd/vhosts/domains.conf

##############
### NO SSL ###
##############
<VirtualHost *:80>
DocumentRoot "/var/www/vhost/domain.com/"
ServerName www.domain.com
<Directory /var/www/vhost/domain.com/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
<Directory "/var/www/vhost/domain.com/secure_domain">
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/httpd/.htpasswd
Require valid-user
</Directory>
</VirtualHost>

###########
### SSL ###
###########

<VirtualHost *:443>
DocumentRoot "/var/www/vhost/domain.com/"
ServerName www.domain.com
ErrorLog logs/ssl_error_log
TransferLog logs/ssl_access_log
LogLevel warn
SSLEngine on
SSLProtocol -all +TLSv1 +TLSv1.1 +TLSv1.2
SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5:!SEED:!IDEA
SSLCertificateFile /etc/pki/tls/certs/www_domain_com.crt
SSLCertificateKeyFile /etc/pki/tls/private/www_domain_com.key

<Directory /var/www/vhost/domain.com/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
<Directory "/var/www/vhost/domain.com/secure_domain">
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/httpd/.htpasswd
Require valid-user
</Directory>
</VirtualHost>
Generating a .htpasswd:
htpasswd -c /var/www/vhost/domain.com/secure_domain username

The SSL conf << /etc/httpd/conf.d/ssl.conf >> should look like this

Listen 443 https
SSLPassPhraseDialog exec:/usr/libexec/httpd-ssl-pass-dialog
SSLSessionCache shmcb:/run/httpd/sslcache(512000)
SSLSessionCacheTimeout 300
SSLRandomSeed startup file:/dev/urandom 256
SSLRandomSeed connect builtin
SSLCryptoDevice builtin

Nginx vhost: