0

I have a website www.example.com that is hosted on apache2 web server in /var/www/example.com directory and the virtual host config file is

<VirtualHost *:80>
    ServerAdmin admin@gmail.com
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com/public
    <Directory /var/www/example.com/public/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <IfModule mod_dir.c>
        DirectoryIndex index.php index.pl index.cgi index.html index.xhtml >
    </IfModule>
</VirtualHost>

I have installed let's encrypt certificate for this domain.

Now I have to change configuration settings and the config file should be like this:

<VirtualHost *:80>
    ServerAdmin admin@gmail.com
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com/dist //here is the change
    <Directory /var/www/example.com/dist/> //here is the change
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <IfModule mod_dir.c>
        DirectoryIndex index.php index.pl index.cgi index.html index.xhtml >
    </IfModule>
</VirtualHost>

I have edited the config file and ran command certbot --apache -d example.com -d www.example.com. Chose reinstall and renew both options and the installation was successful in both cases. But when I go to example.com then it shows 404 error. How can I solve my problem?

Yeasir Arafat
  • 1,425
  • 1
  • 13
  • 28

1 Answers1

1

HTTPS uses port 443, not port 80. Port 443 is closed. You need to add a new virtual host to handle HTTPS request

<VirtualHost *:443>
        ServerName example.com
        #ServerAlias www.example.com
        ServerAdmin admin@gmail.com
        DocumentRoot /var/www/example.com/dist
        LogLevel debug  ssl:info
        SSLEngine on
        SSLCertificateFile /path/to/yout/cert
        SSLCertificateKeyFile //path/to/yout/key
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

If you check ports.conf under /etc/apache2, you will see this:

<IfModule ssl_module>
    Listen 443
</IfModule>

Apache2 will open port 443 when the SSL module is enabled. So remember to run:

sudo a2dismod ssl
sudo systemctl restart apache2
Algo7
  • 2,122
  • 1
  • 8
  • 19