So I have been working on a Badgr server for another department. I have built it using Python 2.7 and django. From what I have heard Django is only used for dev websites.
I want to take this project and convert it to run on something meant for a production environment. But I really have no idea how to proceed. Sorry if this is a really noob question, I am a system administrator not a dev.
(env)[root@badgr code]# ./manage.py runserver & Performing system checks...
System check identified no issues (0 silenced). August 08, 2016 - 16:31:48 Django version 1.7.1, using settings 'mainsite.settings' Starting development server at #####//127.0.0.1:8000/ Quit the server with CONTROL-C.
But I can't seem to connect to it when I go to #####//myserver:8000,
I know the traffic from my PC is hitting the server because I see it in tcpdump on TCP 8000. I have been told runserver blocks traffic from external sources because of it being meant for dev only.
After talking with some people they recommend that I switch to Apache or Gunicorn?
Here are some instructions I was sent from the Django documentation: https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/ Although I can't really make heads or tails of what I should do. Any input would be appreciated. Thanks
I recommend you to use gunicorn and Nginx to run a Django project on your production server. Both are easy to google for official docs and recipes, and their combination is one of the fastest, as long as your code is not to slow. (Nginx+uWSGI is another good option, but a bit harder for beginners).
Gunicorn can be installed with pip install unicorn
or the same way you installed Django and then launched with simple gunicorn yourproject.wsgi
(refer to docs for more configuration options).
Nginx (use your distribution's package manager to install it) should be configured for reverse proxy mode and also to serve static/media files from your respective static/media root (manage.py collectstatic
must be used to keep static files up-to-date). Read documentation to understand basic principles and use this except as an example for your /etc/nginx/sites-enabled/yoursite.conf
:
server {
listen 80 default;
server_name example.com;
root /path/to/project/root/static;
location /media {
alias /path/to/project/root/media;
}
location /static {
alias /path/to/project/root/static;
}
location /favicon.ico {
alias /path/to/project/root/static/favicon.ico;
}
location / {
proxy_pass http://localhost:8000;
include proxy_params;
}
}
There's more to it if you need ssl or www/non-www redirect (both are highly recommended to set up) but this example should be enough for you to get started.
To run gunicorn automatically you can either use supervisor or system unit system (be it systemd or something else).
Note: All of this assumes you're using linux. You probably should not use anything else on a production server anyway.
Consider getting some professional help if you feel you can't understand how to deal with all this, there are many freelance sysadmins who would be happy to help you for a reasonable fee.