具有 SSL 配置的 Apache 不适用于 Django 应用程序的 WSGI 配置

Aru*_*Das 2 django ssl apache2 lets-encrypt certbot

这是 github 上以下问题的后续:

https://github.com/certbot/certbot/issues/1820

https://github.com/certbot/certbot/issues/2546

Letsencrypt无法处理apache的WSGI配置

我正在使用以下配置运行 apache2

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        # DocumentRoot /var/www/html
        ServerName mywebsitedomain.com
        ServerAlias www.mywebsitedomain.com
        DocumentRoot /var/www/html/mywebsitedomain-com

        Alias /static/ /home/ubuntu/Sites/mywebsitedomain-com/myproductionfolder/static/
        <Directory /home/ubuntu/Sites/mywebsitedomain-com/myproductionfolder/static>
                Require all granted
         </Directory>

        # adjust the following line to match your Python path 
        <Directory "/home/ubuntu/Sites/mywebsitedomain-com/myproductionfolder">
        <Files wsgi.py>
                AllowOverride all
                Options FollowSymLinks
                Require all granted
        </Files>
        </Directory>

        WSGIDaemonProcess mywebsitedomain.com processes=2 threads=15 display-name=%{GROUP} user=www-data group=www-data python-path=/home/ubuntu/Sites/mywebsitedomain-com:/home/ubuntu/Sites/mywebsitedomain-com/venv/lib/python3.5/site-packages
        WSGIProcessGroup mywebsitedomain.com
        WSGIScriptAlias / /home/ubuntu/Sites/mywebsitedomain-com/myproductionfolder/wsgi.py process-group=mywebsitedomain.com application-group=%{GLOBAL}


        Alias /phpmyadmin /var/www/html/phpmyadmin
        <Location /phpmyadmin>
        </Location>

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

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

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf

</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

当我按照此处概述的步骤操作时

https://certbot.eff.org/lets-encrypt/ubuntuxenial-apache

如下 :

$ sudo apt-get update
$ sudo apt-get install software-properties-common
$ sudo add-apt-repository ppa:certbot/certbot
$ sudo apt-get update
$ sudo apt-get install python-certbot-apache 
$ sudo certbot --apache
Run Code Online (Sandbox Code Playgroud)

它失败并出现以下错误

Error while running apache2ctl configtest.
Action 'configtest' failed.
The Apache error log may have more information.

AH00526: Syntax error on line 31 of /etc/apache2/sites-enabled/mywebsitedomain.app.conf:
Name duplicates previous WSGI daemon definition.

Rolling back to previous server configuration...
Error while running apache2ctl configtest.
Action 'configtest' failed.
Run Code Online (Sandbox Code Playgroud)

因此,如以下链接所述:

https://github.com/certbot/certbot/issues/1820

我注释掉了 WSGI 行如下

# WSGIDaemonProcess mywebsitedomain.com processes=2 threads=15 display-name=%{GROUP} user=www-data group=www-data python-path=/home/ubuntu/Sites/mywebsitedomain-com:/home/ubuntu/Sites/mywebsitedomain-com/venv/lib/python3.5/site-packages
# WSGIProcessGroup mywebsitedomain.com
# WSGIScriptAlias / /home/ubuntu/Sites/mywebsitedomain-com/myproductionfolder/wsgi.py process-group=mywebsitedomain.com application-group=%{GLOBAL}
Run Code Online (Sandbox Code Playgroud)

并再次运行 certbot,如下所示:

$ sudo certbot --apache

这次,certbot 完成并显示以下消息:

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/mywebsitedomain.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/mywebsitedomain.com/privkey.pem
Run Code Online (Sandbox Code Playgroud)

但是,当我从生成的代码中取消注释以下 3 行时

/etc/apache2/sites-available/mywebsitedomain.com-le-ssl.conf 文件

如下 :

WSGIDaemonProcess mywebsitedomain.com processes=2 threads=15 display-name=%{GROUP} user=www-data group=www-data python-path=/home/ubuntu/Sites/mywebsitedomain-com:/home/ubuntu/Sites/mywebsitedomain-com/venv/lib/python3.5/site-packages
WSGIProcessGroup mywebsitedomain.com
WSGIScriptAlias / /home/ubuntu/Sites/mywebsitedomain-com/myproductionfolder/wsgi.py process-group=mywebsitedomain.com application-group=%{GLOBAL}
Run Code Online (Sandbox Code Playgroud)

并运行

$ sudo 服务 apache2 启动

Apache 似乎已启动,但网站https://mywebsitedomain.com未加载

http://mywebsitedomain.com也没有

请帮助调试这个问题,以便我可以使用 https 来加载 apache 上 django 应用程序的 wsgi 配置。

Ami*_*lil 5

我按照此链接https://www.spmuck.com/https-apache-and-lets-encrypt/上的说明进行操作,它起作用了

这是相关部分:

基本上,当 Certbot 复制虚拟主机文件时,现在将有两个具有相同进程名称的 WSGIDaemonProcess。您可以通过在该行的开头添加 # 注释掉 WSGIDaemonProcess 行来轻松解决此问题。再次运行“certbot --apache”,删除两个虚拟主机文件中的注释,并重命名其中一个进程。即 example.com-le。