[英]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>
我已經為這個域安裝了讓我們加密證書。
現在我必須更改配置設置,配置文件應該是這樣的:
<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>
我已經編輯了配置文件並運行了命令certbot --apache -d example.com -d www.example.com
。 選擇reinstall
和renew
這兩個選項,兩種情況下都安裝成功。 但是當我 go 到example.com
然后它顯示404 error
。 我該如何解決我的問題?
HTTPS 使用端口 443,而不是端口 80。端口 443 已關閉。 您需要添加一個新的虛擬主機來處理 HTTPS 請求
<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>
如果您檢查/etc/apache2
下的ports.conf
,您將看到:
<IfModule ssl_module>
Listen 443
</IfModule>
Apache2 將在啟用 SSL 模塊時打開端口 443。 所以記得運行:
sudo a2dismod ssl
sudo systemctl restart apache2
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.