0

I have a server aerv.nl. it has django (a python framework) but when i run the django server it says: server started at: http://127.0.0.1:8000/ how can i let the server run on: http://www.aerv.nl/~filip/ ? (a real url)

DeepSpace
  • 78,697
  • 11
  • 109
  • 154
filipKAAS
  • 11
  • 1
  • 2

2 Answers2

2

You'll have to configure your http server and Django. For example if you're using apache you'll need to go through this:

https://docs.djangoproject.com/en/1.9/howto/deployment/wsgi/modwsgi/

What you're doing here is setting up your server to handle the http requests through your django app.

MarkHarley
  • 116
  • 7
  • I can give a more detailed answer if you could give a little more detail as to your server setup (and provider). E.g. are you using apache, unicorn, nginx, ... and is this hosted on webfaction, linode, ... – MarkHarley Dec 13 '15 at 13:36
1

You will need to understand how DNS works, then use redirecting and then some proper server (like nginx or apache with e.g. gunicorn), not django development server, which shouldn't be used on production. There is no way you could do what you ask for just with ./manage runserver. All you can do is to change IP address and port to something different by e.g.: ./manage.py runserver 192.168.0.12:9999 so for example other computers in your network might access your site on this specific IP and port.

Example

You are owner of domain example.com, you have server where you want to server your site with IP address e.g. 5.130.2.19. You need go to your domain provider and add an A record which connects these together: example.com -> 5.130.2.19.

Then on your server you set up webserver, e.g. nginx and let it run with e.g. this config for your particular server/site:

server {

    listen   80;
    server_name example.com;

    client_max_body_size 4G;

    location /static/ {
        autoindex on;
        alias   /var/www/example/django/static/;
    }

    location /media/ {
        autoindex on;
        alias   /var/www/example/django/media/;
    }

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_set_header Host $http_host;

        proxy_redirect off;

        if (!-f $request_filename) {
            proxy_pass http://upstream_server;
            break;
        }
    }

upstream upstream_server {
  server unix:/var/www/example/gunicorn.sock fail_timeout=10s;
}

then you would need to run gunicorn with something like

gunicorn example.wsgi:application --bind=unix:/var/www/example/gunicorn.sock 

That should be all, but it's of course very brief. Just substitute example.com for your URL. It is up to you if this going to be specific record in nginx config (think about this as an entry point) or if it is going to be one of route specified in your django project.

How does it work?

User put example.com into an address bar, your computer then ask global DNS servers: To what IP address example.com points to?, DNS reply: It's 5.130.2.19. User's browser then sends HTTP request on that IP, where nginx get this request and looks inside its config if there is example.com handler. It find that it is there and that he should look for files in unix:/var/www/example/gunicorn.sock. He looks there and see working gunicorn, which basically parse python django project to something what nginx can present as your website.

kotrfa
  • 1,191
  • 15
  • 22
  • aha! so when i do that but point it to http://aerv.nl/~filip it will work? or do i have to change the HTTPD config? – filipKAAS Dec 13 '15 at 13:20
  • It really depends on your configuration as a whole. I update my answer to give you a brief idea. – kotrfa Dec 13 '15 at 13:22