Django REST AngularJS NGINX Config

I installed the server according to this guide: https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-14-04

Everything works fine, but I would like to modify my NGINX to enable AngularJS for the interface. Right now I have it configured, as the tutorial says, and when I am in myip / I get my Django application and when I go to myip / static / I get my static files. Fine.

What I would like to do is serve the Django API from the api.myip subdomain and have myip / actually point to my static (angular app) files.

Any insight on how to configure NGINX for proper routing?

NGINX Config now looks like this:

server {
    listen 80;
    server_name server_domain_or_IP;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/user/myproject;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/user/myproject/myproject.sock;
    }
}
+4
source share
1 answer

try it

server {
    listen 80;
    server_name server_domain_or_IP;

    location = /favicon.ico { access_log off; log_not_found off; }
    location / {
        root /home/user/myproject;
    }
}

server {
    listen 80;
    server_name api.server_domain_or_IP;

    location = /favicon.ico { access_log off; log_not_found off; }
    location / {
        include proxy_params;
        proxy_pass http://unix:/home/user/myproject/myproject.sock;
    }
}
+5
source

All Articles