Deploy Django on VPS with custom port

I’ve googling about hot to deploy django on VPS, but mostly i found is just some advice, not tuts. i’ve been confused all of time, in my head just thinking “how to deploy django on VPS with custom port“, yes i have a VPS access (Public IP), but no DNS server, nor domain. All I want is to access mypublicip:someport ex:

After Googling couple times, I’ve found some interesting article, i’ve doing that on my local machine, and everything goes well. but How on Server?

On Server need some setting on your wsgi files and virtual hosts files, these are the setting:

  • wsgi files (example: /PATH/TO/DJANGO/PROJECT/django.wsgi)
  • import os
    import sys
    sys.stdout = sys.stderr
    if path not in sys.path:
    sys.path.insert(0, '/PATH/TO/DJANGO/PROJECT')
    os.environ['DJANGO_SETTINGS_MODULE'] = 'YOUR_PROJECT.settings'
    import django.core.handlers.wsgi
    application = django.core.handlers.wsgi.WSGIHandler()
  • apache virtual hosts files (/etc/apache2/sites-available/WSGI_PROJECT)
  • Listen
        ServerName localhost
        DocumentRoot /PATH/TO/DJANGO/PROJECT
        <Directory /PATH/TO/DJANGO/PROJECT>
            Order allow,deny
            Allow from all
        WSGIDaemonProcess localhost processes=2 threads=10 display-name=%{GROUP}
        WSGIProcessGroup localhost
        WSGIScriptAlias / /PATH/TO/DJANGO/PROJECT/django.wsgi
  • restart your apache server with this command
> sudo a2ensite WSGI_PROJECT
> sudo /etc/init.d/apache2 reload

try to open and your project is accesible on your server.

Reading Materials:

  1. Virtual Hosts Doc
  2. Django Project Documentation files

2 thoughts on “Deploy Django on VPS with custom port

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s