How to tell mod_wsgi-express about MEDIA_ROOT and MEDIA_URL

144 views
Skip to first unread message

Tanuka Dutta

unread,
Mar 9, 2016, 3:09:36 AM3/9/16
to modwsgi
Hello,

I've been trying to upload and then serve user-uploaded files on my website built using Django 1.8.8 and running on Apache 2.2.15, with mod_wsgi version 4.4.23.

Per this blog

the media files are also supposed to be also located/served from the same locations as specified by STATIC_ROOT and STATIC_URL in Django settings.

But latest versions of Django disallow that, and I get this error if they are the same.

 File "/home/syt_admin/.virtualenvs/vishwaas_env/lib/python2.7/site-packages/django/contrib/staticfiles/utils.py", line 56, in check_settings
    raise ImproperlyConfigured("The MEDIA_URL and STATIC_URL "
ImproperlyConfigured: The MEDIA_URL and STATIC_URL settings must have different values

I used the following options to generate the httpd.conf

(vishwaas_env)[syt_admin@VM1 vishwaas_django]$ python manage.py runmodwsgi --setup-only  --https-port=443 --port=80 --server-name=www.xyz.in --user=apache --group=apache --server-root=/home/syt_admin/projects/vishwaas/www-https --ssl-certificate-file=/home/syt_admin/projects/vishwaas/www-https/startssl-certs/2_www.xyz.in.crt --ssl-certificate-key-file=/home/syt_admin/projects/vishwaas/www-https/startssl-certs/server.key --ssl-certificate-chain-file=/home/syt_admin/projects/vishwaas/www-https/startssl-certs/1_root_bundle.crt

Since I am using runmodwsgi, I did not specify the --url-alias. The static directive is automatically generated in my httpd.conf as follows:

Alias '/static' '/home/syt_admin/projects/vishwaas/vishwaas_django/collected_static'

<Directory '/home/syt_admin/projects/vishwaas/vishwaas_django/collected_static'>
    Order allow,deny
    Allow from all
</Directory>

But there is no directive corresponding to /media.

I then manually edited httpd.conf and added the following lines:

Alias '/media' '/home/syt_admin/projects/vishwaas/www-https/media'

<Directory '/home/syt_admin/projects/vishwaas/www-https/media'>
    Order allow,deny
    Allow from all
</Directory>

Now I am able to serve the user-uploaded files on the website.

My question is - how should I tell mod_wsgi-express to generate these directives automatically?

I guess I could use the --url-alias option but it takes two pieces of info (URL-PATH and DIRECTORY-PATH), so how do I specify it using 'python manage.py runmodwsgi'?
What is the syntax?

Please advise what is the best practice here.

Regards,
Tanuka

Graham Dumpleton

unread,
Mar 9, 2016, 4:35:42 AM3/9/16
to mod...@googlegroups.com
Have you tried adding at the end of your runmodwsgi command:

    —url-alias /media /home/syt_admin/projects/vishwaas/www-https/media

That should be all that is required.

If Django has a first class concept of a media directory now and will when running the development server automatically serve up files based on MEDIA_ROOT and MEDIA_URL, then the Django integration for mod_wsgi-express probably should be updated to handle it automatically.

Graham

--
You received this message because you are subscribed to the Google Groups "modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modwsgi+u...@googlegroups.com.
To post to this group, send email to mod...@googlegroups.com.
Visit this group at https://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.

Tanuka Dutta

unread,
Mar 9, 2016, 4:49:16 AM3/9/16
to mod...@googlegroups.com
I get this error:

Usage: manage.py runmodwsgi [options]

Starts Apache/mod_wsgi web server.

manage.py: error: no such option: --url_alias

Regards,
Tanuka

--
You received this message because you are subscribed to a topic in the Google Groups "modwsgi" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/modwsgi/XhvKm3jVV38/unsubscribe.
To unsubscribe from this group and all its topics, send an email to modwsgi+u...@googlegroups.com.

Graham Dumpleton

unread,
Mar 9, 2016, 4:50:41 AM3/9/16
to mod...@googlegroups.com
It is --url-alias, not --url_alias.

Tanuka Dutta

unread,
Mar 9, 2016, 4:57:00 AM3/9/16
to mod...@googlegroups.com
Yes, this worked:

python manage.py runmodwsgi --setup-only  --https-port=443 --port=80 --server-name=www.xyz.in --user=apache --group=apache --server-root=/home/syt_admin/projects/vishwaas/www-https --ssl-certificate-file=/home/syt_admin/projects/vishwaas/www-https/startssl-certs/2_www.xyz.in.crt --ssl-certificate-key-file=/home/syt_admin/projects/vishwaas/www-https/startssl-certs/server.key --ssl-certificate-chain-file=/home/syt_admin/projects/vishwaas/www-https/startssl-certs/1_root_bundle.crt   —url-alias /media /home/syt_admin/projects/vishwaas/www-https/media

The generated httpd.conf now contains the /media directive, and I've tested that the user-uploaded file is served on the website.

It's a bit counter-intuitive because all the other options are in the form

--option=value

whereas this one is separated by spaces.

Probably needs to be added to the documentation?

Regards,
Tanuka

Graham Dumpleton

unread,
Mar 9, 2016, 4:59:01 AM3/9/16
to mod...@googlegroups.com
All the other options can be written without the ‘=‘.

    --https-port 443

It is how the Python argument parser works.

Tanuka Dutta

unread,
Mar 9, 2016, 5:00:13 AM3/9/16
to mod...@googlegroups.com
Thanks, I didn't know that.

- Tanuka
Reply all
Reply to author
Forward
0 new messages