By abhisekdutta
Hi all,
I have a strange problem. I have multiple domains mapped to one droplet. All of them are working fine. Now, I added a new domain, say, example.com. This new domain has two other subdomains app.example.com and engine.example.com. app is nodejs app and it’s working fine. engine is wordpress instance and it’s working fine, too. Now, I want the main domain example.com to show contents from /var/www/example.com/public_html. The .conf file looks like this:
<VirtualHost *:80>
ServerAdmin hi@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/public_html
Redirect / https://www.example.com/
<Directory /var/www/example.com/public_html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin hi@example.com
ServerAlias www.example.com
ServerName example.com
DocumentRoot /var/www/example.com/public_html
<Directory /var/www/example.com/public_html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Require all granted
</Directory>
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/*.example.com/fullchain.pem
SSLCertificateKeyFile /etc/apache2/ssl/*.example.com/key.pem
SSLProtocol all -SSLv2 -SSLv3
SSLHonorCipherOrder on
SSLCipherSuite "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH+aRSA+RC4 EECDH EDH+aRSA RC4 ! aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS"
</VirtualHost>
</IfModule>
Looks fine to me. Except that visiting example.com does not redirect to https://www.example.com. Instead, visiting example.com shows contents from /var/www/html. However, visiting https://www.example.com shows contents from /var/www/example.com/public_html/
What am I missing here?
Also, if it helps, the cname record is
www.example.com example.com
and the a record is
example.com my.droplet.ip
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hello,
Your Vhost looks all good, what I could suggest is to try and update your Redirect rule to:
RewriteEngine on
RewriteCond %{SERVER_NAME} = example.com [OR]
RewriteCond %{SERVER_NAME} =www. example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
Hope that this helps! Regards, Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.