The setup that I use right now relies on Nginx to handle static files and goes to Gunicorn when there's a need to interface with Python.
I update the files on the server by using 'git push live master,' where 'live' is the name of a repository on the server that has hooks set to update a directory that lives in Django. That directory includes the static files (css, js) that my pages rely on.
It is possible to configure Django to automatically copy all static files to a single location. Then all you need to do make sure that that location is the one that your nginx configuration points at. See the docs here.
In my case, I keep all my static files gathered under a directory named "static" so I just pointed Nginx at that directory. It's reasonably likely that I'll need to change that pointer at some point, so I'm writing a reminder of what I had to do right here.
First I found the relevant configuration file for nginx. On my Ubuntu VPS that file was under
/etc/nginx/sites-available/username
where 'username' was the user that I was set up under. There is also a default configuration file, which would be used in the absence of the more specific username configuration.
Second, in that file I altered the following address to point directly to my static directory
location /static {
alias /home/path/to/my/static/directory;
}
Third, I refreshed nginx:
sudo nginx -reload
Fourth: There was no fourth step. That's it!
Recursive algorithms can be slow because they end up solving the same little problems over and over again. To speed them up, you can use a technique called "memoization." Memoization allows algorithms go much more quickly by remembering solutions to problems they have already solved. I’m the recursive algorithm. This blog is my memoization.
Showing posts with label nginx. Show all posts
Showing posts with label nginx. Show all posts
Tuesday, November 25, 2014
Configuring nginx to serve static files in django
Wednesday, November 5, 2014
nginx, postgresql, django, virtualenv
Nice tutorial here on Digital Ocean:
https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-django-with-postgres-nginx-and-gunicorn
The instructions fell apart a bit once I got to the section configuring postgres. Basically, when I expected to see a query about a role name it skipped that and started asking me about a password.
So for the configuration of postgres on Ubuntu, I recommend skipping over to https://help.ubuntu.com/community/PostgreSQL .
After that I went back to the guide.
I found that since I was using python3 and because of a bug in 'pip' where it wants to install things globally, I had to change the
'pip install psycopg2' inside my virtual environment to
'pip3 install psycopg2' to get a local installation with python3.
Next, there is a depracated command in the tutorial that no longer works.
Replace
https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-django-with-postgres-nginx-and-gunicorn
The instructions fell apart a bit once I got to the section configuring postgres. Basically, when I expected to see a query about a role name it skipped that and started asking me about a password.
So for the configuration of postgres on Ubuntu, I recommend skipping over to https://help.ubuntu.com/community/PostgreSQL .
After that I went back to the guide.
I found that since I was using python3 and because of a bug in 'pip' where it wants to install things globally, I had to change the
'pip install psycopg2' inside my virtual environment to
'pip3 install psycopg2' to get a local installation with python3.
Next, there is a depracated command in the tutorial that no longer works.
Replace
gunicorn_django --bind yourdomainorip.com:8001
withgunicorn myapp.wsgi:application --bind yourdomainorip:8001
Subscribe to:
Posts (Atom)