使用 Django 项目时显示 HTTPS 的 Apache 默认页面

使用 Django 项目时显示 HTTPS 的 Apache 默认页面

过去一周我一直在尝试让它工作,但似乎根本不起作用。请帮忙,这是 default-ssl 和 001-default 的文件,网站在 http 上运行良好,但在 https 上运行不正常。-

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerAdmin [email protected]
    ServerName essayeshop.com
    ServerAlias www.essayeshop.com
    DocumentRoot /var/www/html

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

    SSLEngine on

    SSLCertificateFile /etc/apache2/ssl/apache.crt
    SSLCertificateKeyFile /etc/apache2/ssl/apache.key

    <FilesMatch "\.(cgi|shtml|phtml|php)$">
            SSLOptions +StdEnvVars
    </FilesMatch>
    <Directory /usr/lib/cgi-bin>
            SSLOptions +StdEnvVars
    </Directory>

    BrowserMatch "MSIE [2-6]" \
            nokeepalive ssl-unclean-shutdown \
            downgrade-1.0 force-response-1.0
</VirtualHost>

ServerName essayeshop.com
ServerAdmin [email protected]
DocumentRoot /var/www/html
# 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


Alias /static /home/nick/website/static
<Directory /home/nick/website/static>
    Require all granted
</Directory>

<Directory /home/nick/website/website>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>

WSGIDaemonProcess website python-path=/home/nick/website python-home=/home/nick/website/env
WSGIProcessGroup website
WSGIScriptAlias / /home/nick/website/website/wsgi.py
# 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

答案1

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

  WSGIDaemonProcess essayeshop.com \
    python-home=/path/to/.virtualenv/mysite/ \
    python-path=/path/to/mysite/

  WSGIScriptAlias / /path/to/mysite/wsgi.py \
   process-group=mysite.com \
   application-group=%{GLOBAL}

  <Directory /path/to/mysite>
    <Files wsgi.py>
      Require all granted
    </Files>
  </Directory>

  <Directory /path/to/.virtualenvs/mysite>
    Require all granted
  </Directory>

  <Directory /path/to/mysite/logs>
    Require all granted
  </Directory>

  Alias /media/ /path/to/mysite/media/
  Alias /static/ /path/to/mysite/static/

  ErrorLog /var/log/apache2/mysite-error.log
  LogLevel warn
  CustomLog /var/log/apache2/mysite-access.log combined

  SSLEngine on
  SSLCertificateFile /path/to/cert/cert.pem
  SSLCertificateKeyFile /path/to/cert/privkey.pem
</VirtualHost>
</IfModule>

我们需要安装mod-wsgi,它是用于实现python WSGI的apache模块。

启用站点和所需模块

a2enmod ssl rewrite headers wsgi alias

并重新启动 apache 服务

相关内容