0

我想在 Apache 2.4 服务器上部署我的 django 应用程序。同一台服务器将托管静态文件。问题是该服务器托管其他基于 php 的网站。为了让所有这些工作我只需要安装和配置与这个网站相关mod_wsgi的 apache文件,对吗?.conf

在阅读了几篇文章后,我想出了这个配置,假设网站将在var/www/文件夹中:

<VirtualHost *:80>
ServerName example.com
#   Alias /events /var/www/events/html
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/example

            Alias /media/ /var/www/example/media/
            Alias /static/ /var/www/example/static/

            <Directory /var/www/example/static>
            Order deny,allow
            Require all granted
            </Directory>

            <Directory /path/to/example/media>
            Order deny,allow
            Require all granted
            </Directory>

            WSGIScriptAlias / /var/www/example/events_promgruz/wsgi.py
            WSGIDaemonProcess example.com python-path=/var/www/example:/opt/envs/lib/python3.6/site-packages
            WSGIProcessGroup example.com

            <Directory /path/to/example/example>
            <Files wsgi.py>
            Order allow,deny
            Require all granted
            </Files>
            </Directory>

    LogLevel debug
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>

您会建议更改或添加到配置中吗?是否有其他一些步骤来确保 django 应用程序能够正常工作并且不会干扰其他非 wsgi 应用程序?

4

1 回答 1

0

这就是我最终使用的:

<VirtualHost *:80>
ServerName expample-domen.com
    ServerAdmin webmaster@localhost
Alias /static /var/www/example/static
Alias /media /var/www/example/media

<Directory /var/www/example/static>
Require all granted
</Directory>

<Directory /var/www/example/media>
    Order deny,allow
    Require all granted
</Directory>

<Directory /var/www/example/example>
<Files wsgi.py>
        Require all granted
    </Files>
</Directory>

    WSGIDaemonProcess example python-home=/path/to/virtualEnv python-path=/var/www/example
    WSGIProcessGroup example
    WSGIScriptAlias / /var/www/example/example/wsgi.py

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

</VirtualHost>
于 2018-11-24T20:51:45.033 回答