Hello! I am unsure on how to setup a subdomain for my website… I have tried many ways to no avail. I intend on making it so that a subdomain (eg: cloud.mywebsite.com) link into a document root /var/www/cloud [With an SSL certificate] I run:
Server version: Apache/2.2.22 (Ubuntu)
Server built: Jul 15 2016 15:32:34
I already have a apache2 VH setup for my domain:
# mywebsite.com main VH
<VirtualHost *:80>
ServerName mywebsite.com
Redirect / https://mywebsite.com
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
ServerName mywebsite.com
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/mywebsite_com.crt
SSLCertificateKeyFile /etc/apache2/ssl/mywebsite.com.key
SSLCertificateChainFile /etc/apache2/ssl/COMODORSAAddTrustCA.crt
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
# mywebsite.com VH ends here...
# cloud.mywebsite.com subdomain starts here...
<VirtualHost *:80>
ServerName cloud.mywebsite.com
Redirect / https://cloud.mywebsite.com
DocumentRoot /var/www/cloud
</VirtualHost>
My apache2.conf: (I have removed majority of the comment the full config is here)
LockFile ${APACHE_LOCK_DIR}/accept.lock
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 150
MaxRequestsPerChild 0
</IfModule>
<IfModule mpm_worker_module>
StartServers 2
MinSpareThreads 25
MaxSpareThreads 75
ThreadLimit 64
ThreadsPerChild 25
MaxClients 150
MaxRequestsPerChild 0
</IfModule>
<IfModule mpm_event_module>
StartServers 2
MinSpareThreads 25
MaxSpareThreads 75
ThreadLimit 64
ThreadsPerChild 25
MaxClients 150
MaxRequestsPerChild 0
</IfModule>
# These need to be set in /etc/apache2/envvars
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
AccessFileName .htaccess
<Files ~ "^\.ht">
Order allow,deny
Deny from all
Satisfy all
</Files>
DefaultType None
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
Include mods-enabled/*.load
Include mods-enabled/*.conf
Include httpd.conf
Include ports.conf
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
Include conf.d/
# Include the virtual host configurations:
Include sites-available/
Unfortunately… I have not been able to set up a subdomain leading into one of the directories before. I am hoping to enlighten myself as most of the tutorials/guides online i’ve seen were quite misleading.
A big thank you in advance.
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
It looks like you don’t have a VirtualHost block for cloud.mywebsite.com on port 443. If you take out the redirect directive, does cloud.mywebsite.com work?