Last active
September 13, 2017 08:04
-
-
Save liveashish/6b7438d1abbb616e8387 to your computer and use it in GitHub Desktop.
Setting Up django
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NB: No need to assign STATICFILE_DIRS before commanding collectstatic | |
1. create project using django-admin.py startproject project | |
2. /project | |
pip install gunicorn | |
3. gunicorn project.wsgi:application #this is for dev and the server dies once you break | |
4. gunicorn test_project.wsgi:application --daemon #for production and gunicorn runs in background | |
5. sudo apt-get install nginx | |
6. STATIC_ROOT = os.path.join(PROJECT_DIR, 'staticfiles/') #"staticfile" folder location in the root i.e. /project/staticfile | |
7. python manage.py collectstatic #this will create the folder staticfile in root and will add all the static files in this dir | |
8. cd /etc/nginx/sites-enabled/ | |
9. sudo nano default | |
events{} | |
http{ | |
server { | |
listen 80; | |
server_name 184.73.125.200; | |
location /static { | |
alias /home/path/to/project/staticfiles; # if my static path is /home/$ eg: /home/ashish/qpcm/staticfiles; | |
# write this here /home/ubuntu/web$ | |
autoindex on; | |
} | |
location / { | |
proxy_set_header X-Real-IP $http_x_forwarded_for; | |
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for; | |
proxy_set_header Host $http_host; | |
proxy_redirect off; | |
if (!-f $request_filename) { | |
proxy_pass http://127.0.0.1:8000; #url of your django server | |
break; | |
} | |
} | |
} | |
} | |
10. In settings.py | |
STATIC_ROOT is the location of your staticfiles | |
STATIC_URL is url of static directory eg: '/static/' for local and 'xyz.com/static' for prod | |
STATICFILES_DIRS is the location of your staticfiles | |
STATIC_ROOT = '/home/ubuntu/qpcm/staticfiles/' | |
STATIC_URL = 'http://54.169.41.175/static/' | |
STATICFILES_DIRS = ( | |
'/home/ubuntu/qpcm/staticfiles/', | |
# Put strings here, like "/home/html/static" or "C:/www/django/static". | |
# Always use forward slashes, even on Windows. | |
# Don't forget to use absolute paths, not relative paths. | |
) | |
11. restart nginx and start gunicorn in daemon! :D |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanx Ashish :D