Save the template as vhost.con in de vhosts.d dir so it won't start.
# cd /etc/http/conf/ # mkdir vhosts.d # cd vhosts.d # vi vhost.con
<VirtualHost *:80> ServerName example.com redirect 301 / http://www.example.com </virtual> <VirtualHost *:80> ServerAdmin webmaster@example.com ServerName www.example.com CustomLog /var/log/httpd/www.example.com-access_log combined ErrorLog /var/log/httpd/www.example.com-error_log HostnameLookups Off UseCanonicalName Off ServerSignature On DocumentRoot /srv/www/vhosts/www.example.com/httpdocs <Directory "/srv/www/vhosts/www.example.com/httpdocs"> Options +Indexes AllowOverride All Require all granted </Directory> </virtual>
When you need CGI scripting add:
ScriptAlias /cgi-bin/ "/srv/www/vhosts/www.example.com/cgi-bin/" <Directory "/srv/www/vhosts/www.example.com/cgi-bin"> Options +ExecCGI -Includes AllowOverride None Require all granted </Directory> </VirtualHost>
Now for <url>:
# cd /etc/httpd/conf/vhosts # cp vhost.con <url>.conf
Change www.example.com to the <url> insite the config file.
Between steps you can use ll to see if it went OK.
To check the con (selinux) type ll -Z.
# cd /srv/www # mkdir vhosts # chcon -t httpd_sys_content_t vhosts # cd vhosts # mkdir www.example.com # cd www.example.com # mkdir httpdocs # mkdir cgi-bin # chown root:users httpdocs cgi-bin # chcon -t httpd_sys_script_exec_t cgi-bin
For the use with https you can use httpsdocs instead off httpdocs. This is not required.
# cd /etc/http/conf/vhosts.d # vi www.example.com
<VirtualHost *:80> ServerName example.com Redirect 301 / https://www.example.com/ </VirtualHost> <VirtualHost *:80> ServerName www.example.com Redirect 301 / https://www.example.com/ </VirtualHost> <VirtualHost *:443> ServerAdmin webmaster@example.com ServerName www.example.com CustomLog /var/log/httpd/www.example.com-access_log combined ErrorLog /var/log/httpd/www.example.com-error_log DirectoryIndex index.html index.html.var index.htm index.shtml index.php SSLEngine on SSLCertificateFile /etc/pki/tls/certs/example.com.crt SSLCertificateKeyFile /etc/pki/tls/private/example.com.key SSLCertificateChainFile /etc/pki/tls/certs/example.com_ca-bundle.pem DocumentRoot /srv/www/vhosts/www.example.com/httpsdocs <Directory "/srv/www/vhosts/www.example.com/httpsdocs"> Options +Indexes +FollowSymLinks AllowOverride All Require all granted </Directory> ScriptAlias /cgi-bin/ "/srv/www/vhosts/www.example.com/cgi-bin/" <Directory "/srv/www/vhosts/www.example.com/cgi-bin"> Options +ExecCGI -Includes SSLOptions +StdEnvVars AllowOverride None Require all granted </Directory> </VirtualHost>
This can be repeated for blog.example.com, cloud.example.com ect.
If your website don't need cg-bin then remove the ScriptAlias /cgi-bin/ part.
Now for <url>:
# cd /etc/httpd/conf/vhosts # cp vhosts.con <url>.conf
Change www.example.com to the <url> insite the config file.