Search code examples
apachevirtualhostvpslampvhosts

Setting up LAMP on VPS, virtual host not working


Trying to set up a sample site on a VPS with LAMP. Accessing the site via IP address loads it fine, but I'd like to make it work with the URL "mysite.dev". However when I go to http://mysite.dev in Chrome, I get "This site can’t be reached. mysite.dev refused to connect."

I followed instructions from this article and the configtest is OK: https://linuxize.com/post/how-to-set-up-apache-virtual-hosts-on-ubuntu-20-04/

Port 80 is open.

I did notice when I enter http://mysite.dev in Chrome, it replaces it with https and I can't get that to turn off. Not sure if that's the problem.

Here is the config setup:

/etc/apache2/sites-available/mysite.dev.conf:

<VirtualHost *:80>
    ServerName mysite.dev
    ServerAlias www.mysite.dev
    ServerAdmin [email protected]
    DocumentRoot /var/www/mysite.dev/public_html

    <Directory /var/www/mysite.dev/public_html>
        Options -Indexes +FollowSymLinks
        AllowOverride All
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/mysite.dev-error.log
    CustomLog ${APACHE_LOG_DIR}/mysite.dev-access.log combined
</VirtualHost>

My local /etc/hosts file:

123.123.123.123  mysite.dev
123.123.123.123  www.mysite.dev

Any help is appreciated.


Solution

  • Figured it out. Chrome forces all .dev domains to use HTTPS, which I hadn't configured. Changed to use a different TLD and all is good.