Question

Virtual host returning 404

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!


Submit an answer


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!

Sign In or Sign Up to Answer

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.

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

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

https://community.letsencrypt.org/t/setting-up-letsencrypt-for-a-single-wordpress-multisite-installation-with-many-domains/46511/6

It did with me

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

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel