为 lets-encrypt 和 django 配置 apache

为 lets-encrypt 和 django 配置 apache

我可以使用以下 example.com.conf 文件毫无问题地为 https 设置我的域名:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /www/example.com

    ErrorLog /var/log/example.com/error.log

    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined

    RewriteEngine on

</VirtualHost>

然后我运行 certbot --apache,选择我的域,安装证书,然后选择选项 2:安全 - 使所有请求重定向到安全的 HTTPS 访问。文件 example.com-le-ssl.conf 的创建方式如下:

<IfModule mod_ssl.c>
    <VirtualHost *:443>
        ServerName example.com
        ServerAlias www.example.com
        DocumentRoot /www/example.com

        ErrorLog /var/log/example.com/error.log

        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined

        RewriteEngine on

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

访问 example.com 会重定向到https://example.com并直接转到https://example.com也工作正常。

现在我想更改 apache 配置以与 django 一起使用

我尝试使用底部的 example.com.conf 文件,然后运行 ​​certbot --apache 命令,但它给出了错误

Name duplicates previous WSGI daemon definition.

我也尝试在按上述方法运行后更改文件,但没有成功。有知道如何正确执行此操作吗?

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    WSGIPassAuthorization On


    WSGIDaemonProcess myapp  python-home=/opt/MyProject-Master python-path=/opt/MyProject-Master/MyProject processes=2 threads=5

    WSGIProcessGroup myapp
    WSGIScriptAlias / /path/MyProject-Master/MyProject/MyProject/wsgi.py process-group=myapp
    <Directory /path/MyProject-Master/MyProject/MyProject>
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>

    ErrorLog /var/log/example.coms/error.log

    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined

</VirtualHost>

答案1

在注释掉 WSGI 行时运行 certbot --apache 命令,然后在运行命令后取消注释。希望有所帮助...

#WSGIDaemonProcess myapp  python-home=/opt/MyProject-Master python-path=/opt/MyProject-Master/MyProject processes=2 threads=5

#WSGIProcessGroup myapp
#WSGIScriptAlias / /path/MyProject-Master/MyProject/MyProject/wsgi.py process-group=myapp

相关内容