需要帮助的配置Apache .conf文件(Need help configuring apache

2019-10-28 16:07发布

我想部署的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应用程序?

Answer 1:

这是我最终使用:

<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>


文章来源: Need help configuring apache .conf file