0

Problem: all urls go to my landing page, including a basic '/about' and '/contact'

Example: Url www.mydomain.com works perfectly (loads css, etc), but www.mydomain.com/about goes to www.mydomain.com even though it says www.mydomain.com/about in address bar.

Question: How do I configure nginx to simply pass everything through to django?

I'm deploying a website I've written locally using django to an EC2 instance. I am able to access my default landing page, but I can't access any other page. I have a basic site with /about, /contact mappings, but when I go to them I simply am redirected to my landing page. I'm pretty sure that this has something to do with my nginx config, but after looking through basic nginx tutorials I don't think I'm grasping what I'm missing.

Here is my conf file for nginx...

server {
  listen 80;
  server_name mydomain.com;
  access_log /var/log/nginx/sample_project.access.log;
  error_log /var/log/nginx/sample_project.error.log;

  # https://docs.djangoproject.com/en/dev/howto/static-files/#serving-static-files-in-production
  location /static/ { # STATIC_URL
      alias /home/ubuntu/path/to/static/; # STATIC_ROOT
      expires 30d;
  }

  location /media/ { # MEDIA_URL
      alias /home/ubuntu/path/to/static/; # MEDIA_ROOT
      expires 30d;
  }

  # I have also tried 'location ~* ^(.*?)$' and it had the same effect
  location / {
      include fastcgi_params;
      fastcgi_pass 127.0.0.1:8080;
  } 
}

As I read through nginx tutorials/etc, I can appreciate that it can do a lot, but I would prefer to handle all incoming urls through django.

Dave
  • 6,141
  • 2
  • 38
  • 65

2 Answers2

0

I Configured my Django Site using Gunicorn + Nginx on EC2 and it works fine for me. Steps are here

Community
  • 1
  • 1
Rakesh
  • 81,458
  • 17
  • 76
  • 113
  • I'm seeing this message when trying to start nginx: `Starting nginx: nginx: [emerg] "upstream" directive is not allowed here` Any ides on why that could be happening? – Dave Aug 14 '12 at 13:20
  • Can u show me ur nginx.conf, i had a typo error in my answer. i changed 'upstream app_server_hana' to 'upstream app_server_site1' – Rakesh Aug 15 '12 at 08:27
0

I just ended up using this nginx conf file and it began to work fine. I think it was probably the addition of one of the arguments to the location element that did the trick.

https://code.djangoproject.com/wiki/ServerArrangements

Dave
  • 6,141
  • 2
  • 38
  • 65