Django + Lighttpd - django

I am having some trouble getting django and lighttpd setup.
Here ist what I want to do:
Have lighttpd manage the fascgi processes (they both are run on the same server)
Have the django app run at the root of the site (so no django.fcgi)
Alternativly I could start django on startup, but I would need a start/stop script for ubuntu/debian.
Also how do I handle the media / admin media urls? Also I would like to serve /css /js /img from the document root ...
TIA
Patrick

Please see:
https://github.com/cdsi/elrond/blob/master/etc/lighttpd.conf
https://github.com/cdsi/elrond/blob/master/var/www/elrond.wsgi
Be sure to update the env.ELROND_XXX paths accordingly, and change:
fastcgi.server = ("/elrond" =>
to:
fastcgi.server = ("/" =>

Related

Django + GUnicorn ASGI with SCRIPT_NAME

I have a Django application running with a gunicorn ASGI server and an NGINX reverse proxy for serving static content. All are packaged within a docker container.
Now I want to serve this container behind a reverse proxy with a path prefix, e.g. "mydomain.com/djangoapp/". The problem is, that Django doesn't know it's hosted under a subpath, and for example, the Django admin application then always redirects to the root path "/" instead of "/djangoapp/".
I already read that there are several settings that handle this problem.
I tried setting the "FORCE_SCRIPT_NAME" in the Django settings directly to "/djangoapp". It worked for the admin login page, but after clicking the login button it redirected to the wrong root "/".
I tried setting the "SCRIPT_NAME" environment variable of the gunicorn server to "/djangoapp". It did not apply at all.
I'm running now out of ideas on what else to try. Does anybody else have a solution for this problem?
FORCE_SCRIPT_NAME should work. For the post-login redirect you need to properly set LOGIN_REDIRECT_URL

Deploy Django in subdomains

I want to deploy a django app into an existing webenvironment, with other sites already existing.
Therefore i received a domain from the webadmin like this: www.websites.com/theapp
Now, in my local development environment the path /theapp does not exist, because the project is starting on / and the project folder is called /myapp
Myapp's urls.py is pointing to two included apps like /app1 and /app2
I tried to add /theapp to the urls, what really doesn't work.
As i am fairly new to Django i would appreciate any assistance on how to handle this leading path, so Django could handle the incoming url correctly.
First, you should configure Web Server (like nginx, apache, etc...). Below is the Nginx configuration:
location /theapp {
... something uwsgi configuration or proxy_pass things ...
}
After that, set up Django's urls.py file to accept requests starting with the path /theapp.
from django.urls import path, include
urlpatterns = [
path('theapp/', include('yourapp.urls')),
]

Static (admin) files do not seem to be served correctly

I have problems with Django serving static files on the admin panel.
Calling http://vbox.me/admin/ (where vbox.me is aliased to the VM's IP) results in a blank page without stylesheets.
Calling http://vbox.me/static/admin/css/base.css though, which is part of the stylesheets that should be loaded when opening http://vbox.me/admin/, brings up the correct file.
Here is some essential information:
I recently started experimenting with Django.
My current version of Django is 1.8.
I'm running nginx (on Arch Linux within a VirtualBox on Windows 7) that passes every non-static file to uwsgi
uwsgi and nginx run as service using systemd
Running the Django development server standalone does not result in the given weird behavior.
Nginx configuration file:
# ...
http {
sendfile on;
upstream django {
server unix:/tmp/uwsgi.sock;
}
server {
# ...
location /static {
# static directory of the django project
alias /home/martin/projects/django_test/static;
}
location / {
uwsgi_pass django;
include /etc/nginx/uwsgi_params;
}
}
}
INI file for uwsgi:
[uwsgi]
chdir=/home/martin/projects/django_test
wsgi-file=django_test/wsgi.py
chmod-socket=666
socket=/tmp/uwsgi.sock
master=true
vacuum=true
Important parts from settings.py within the Django project:
STATIC_ROOT = '/home/martin/projects/django_test/static/'
# using vbox.me to make sure the browser does not make up some strange url.
STATIC_URL = 'http://vbox.me/static/'
I'm pretty much "left in the dark", I can only guess that I made some mistake in configuring uwsgi or Django, since nginx seems to server the static files perfectly (at least when explicitly requesting them...)
Thanks in advance!
Edit: I will do a fresh setup of all the tools I use to deploy my app to make sure I made no mistakes. Additionally, I will be using virtualenv this time (which I haven't used previously). I'll let you know if that works!
After doing a fresh install of everything following this tutorial, everything works just fine now. Looks like I made some mistakes in configuration.
I also used Django 1.7 here, so Django 1.8 might have been the cause to my problems as well (though thats really unlikely)

Django-CMS text editing not working on Apache

When serving my django-cms application on apache with mod_wsgi I can't get the text-plugin to work.
The difference is that when serving on apache the textedito tries to get an url that does not exist.
On Apache:
/admin/js/iframe/default/wymiframe.html
With manage.py runserver
/static/cms/wymeditor/iframe/default/wymiframe.html
the wymiframe.html file is present in my static folder and is accessible but not via the wrong URL that I get when running the app through apache.
What do I do to get the text-plugin requesting the right URL?
What have you set STATIC_URL to in your settings file? That in part is what controls paths when links are created.
https://docs.djangoproject.com/en/1.4/howto/deployment/wsgi/modwsgi/#serving-the-admin-files
My problem was that I served static content on a subdomain and I had problems with Access Control.
My solution was to set
Header set Access-Control-Allow-Origin *
in my apache config file

admin site looks different in production environment

so I'm building a basic site to learn django, and i am currently setting up the admin site. when launch the site through
python manage.py runserver
i can go to the website and it looks pretty just like this. http://cl.ly/2Z3A2n0I1E140X3k180h
but when i load the site through my apache web server it looks like this. http://cl.ly/3H3r1G2D193p462t3641
can anyone help me?
it looks to me like the admin site is not able to load the proper template on the live site. but i did not setup any special template. and when i look at the permissions of the template folder it seems to be fine... maybe not. any help?
Ok, sorry for the long story:
First, find out where your django installation rests:
in the CLI:
>>> import django
>>> django
<module 'django' from '/usr/local/lib/python2.6/dist-packages/django/__init__.pyc'>
The this is the path (except for the __init__.pyc, of course) to your Django installation.
Now, in your media directory, you could create a symbolic link to the directory that the admin media is located in (this way you will not have to copy the files to your media directory).
Assuming that you are in your media directory use this command to create dynamic link to the admin media directory (the first argument to ln -s should of course be your django path that we got retrieved earlier):
ln -s /usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/ admin
Now in your settings.py you can use something like this:
MEDIA_URL = 'media'
ADMIN_MEDIA_PREFIX = '/media/admin/
You will also have to add this directive to your Apache config:
Alias /media/ /full/path/to/your/django/site