Need help configuring apache .conf file

2019-08-16 12:52发布

I want to deploy my django app on a Apache 2.4 server. The same server will host static files. The thing is that this server hosts other php based web sites. In order for all this to work I just need to install mod_wsgi and configure apache's .conf file related to this web site, is that right?

After reading few articles I came up with this config, assuming that the web site will be in the var/www/ folder :

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

What would you suggested to change or add to config? Is there some other steps to ensure that django app will work and that it doesn't interfere other non wsgi apps?

1条回答
做自己的国王
2楼-- · 2019-08-16 13:41

This is what I ended up using:

<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>
查看更多
登录 后发表回答