Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
823 views
in Technique[技术] by (71.8m points)

apache2 - Reset project directory of apache web server virtual host having let's encrypt ssl certificate installed

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...