Hi everyone!
I have vhost pointing to certain folder using the main domain and I’m setting up the second one, a subdomain, pointing to another folder. The first one works fine since forever, and the second one never worked, always returning 404. Funny thing is that if I call the IP address it loads the second vhost.
First vhost (working):
<VirtualHost *:80>
ServerAdmin fechagas.dev@gmail.com
ServerName cropflow.com.br
ServerAlias www.cropflow.com.br
DocumentRoot /var/www/html/cropflow
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =cropflow.com.br [OR]
RewriteCond %{SERVER_NAME} =www.cropflow.com.br
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
Second vhos (return 404):
<VirtualHost *:80>
ServerAdmin fechagas.dev@gmail.com
ServerName api.cropflow.com.br
ServerAlias www.api.cropflow.com.br
DocumentRoot /var/www/html/cropflow-api/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =api.cropflow.com.br [OR]
RewriteCond %{SERVER_NAME} =www.api.cropflow.com.br
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
Both vhosts was configured following this article: https://www.digitalocean.com/community/tutorials/como-configurar-apache-virtual-hosts-no-ubuntu-16-04-pt
Thanks in advance!
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!
Accepted Answer
what is the “public” in
DocumentRoot /var/www/html/cropflow-api/public
Are you sure it is in a public folder?
Also you could take out the redirect to https and test it on http only
Your api.cropflow.com.brvhost does a redirect to https://api.cropflow.com.br. So you’d need to look at the SSL/433 vhost and see if it’s properly configured.
$ curl -I api.cropflow.com.br
HTTP/1.1 301 Moved Permanently
Date: Wed, 12 Dec 2018 19:40:01 GMT
Server: Apache/2.4.18 (Ubuntu)
Location: https://api.cropflow.com.br/
Content-Type: text/html; charset=iso-8859-1
Yes I thought it might be the cert. And yes I do have some advice, lets encyrpt doesnt support virtual hosts in one file, so just use the working one and copy the contents too a second conf file and then run the certbot again
this might help
It did with me
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.