Ubuntu上的Apache conf导致url重复自身而不是重定向

问题描述

Ubuntu 18.04 阿帕奇2 Certbot

我正在尝试在此站点上设置cerbot和非www到www重定向,并且正在从另一个工作正常的站点复制conf文件,但是出于某种原因,443被禁止使用该新网站上的用户和非www.domain.url的用户重定向到domain.url / www.domain.urlwww.domain.urlwww.domain.url等。

main.conf

<VirtualHost *:80>                                                                                                 
    ServerName domain.url                                                                                       
    Redirect permanent / https://www.domain.url/                                                         
</VirtualHost>   

<VirtualHost *:80>                                                                                                                                                                                                                                                                                                                                                                                             
    ServerName www.domain.url                                                                                    
    ServerAdmin [email protected]                                                                              
    DocumentRoot /var/www/html
                                                                                                                                                                                         
    ErrorLog ${APACHE_LOG_DIR}/error.log          
                                                                                                                                                                       
    RewriteEngine on                                                                                           
    RewriteCond %{SERVER_NAME} =www.domain.url                                                                  
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]                            
</VirtualHost>                                                                                                                                                                                                        
# vim: Syntax=apache ts=4 sw=4 sts=4 sr noet   

main-le-ssl.conf

<IfModule mod_ssl.c>                                                                                             
    <VirtualHost *:443>                                                                                                                                                                                                                      
        ServerName www.domain.url                                                                                          
        ServerAdmin [email protected]                                                                                 
        ServerAlias domain.url                                                                                            
        DocumentRoot /var/www/html 
        
        RewriteEngine On                                                                                                                                                                                                                  
        RewriteCond %{HTTP_HOST} !^www\. [NC]                                                                            
        RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]                                                                                                                                                                                                                                                  
                                                                                                                                                                                                    
        ErrorLog ${APACHE_LOG_DIR}/error.log                                                                             
        CustomLog ${APACHE_LOG_DIR}/access.log combined   
                                                                                                                                                                                   
        Alias /static /home/user/project/static                                                                     
        <Directory /home/user/project/static>                                                                               
            Require all granted                                                                                      
        </Directory>                                                                                                                                                                                                                      

        <Directory /home/user/project/media>                                                                                
            Require all granted                                                                                      
        </Directory>                                                                                                                                                                                                                      

        <Directory /home/user/project>                                                                                      
            <Files wsgi.py>                                                                                                          
                Require all granted                                                                                      
            </Files>                                                                                                 
        </Directory>   
                                                                                                                                                                                                               
        WsgiScriptAlias / /home/user/project/project/wsgi.py                                                          
        WsgiDaemonProcess theprocess python-path=/home/user/prject python-home=/home/user/project/wow           
        WsgiProcessGroup theprocess                                                                                                                                                                                                 

        Include /etc/letsencrypt/options-ssl-apache.conf                                                                 
        SSLCertificateFile /etc/letsencrypt/live/www.domain.url/fullchain.pem                                              
        SSLCertificateKeyFile /etc/letsencrypt/live/www.domain.url/privkey.pem                                             
    </VirtualHost>                                                                                                   
</IfModule>   

ssh,http,https都已用ufw启用。用户可能可以查看我的网站,但可能存在权限问题,但是在安装certbot之前,它工作正常。现在,所有内容(导致重复域问题的非https非www除外)都重定向https://www.domain.url,并且我收到一条禁止消息。

当我安装certbot时,我错过了非www域。当我返回并重新获得www和non-www时,重定向设置失败,但是它说我有证书。这是问题所在吗?我以为我可以自己在配置文件中建立重定向...

解决方法

此帖子最终成为答案: https://serverfault.com/questions/957788/forbidden-after-enabling-ssl

我的WSGIScriptAlias文件路径出现大小写错误。