I want to run Django with uWSGI behind a NGINX.
I will use Django as a API service which should live on this link: project.test/api The Django project itself is blank (1.9.6), just created a app, migrated and created a superuser.
My Project structure looks like this:
/vagrant/api/here-lives-whole-django
/vagrant/api/uwsgi_params
/vagrant/frontend/some-frontend-work-seperated-from-django
My NGINX setup looks like this:
upstream testing {
server 127.0.0.1:8000;
}
server {
listen 80;
server_name www.testing.test;
charset utf-8;
client_max_body_size 75M;
access_log /var/log/nginx/www.testing.test.access.log;
error_log /var/log/nginx/www.testing.test.error.log;
location /api/ {
include /vagrant/api/uwsgi_params;
uwsgi_pass testing;
}
location / {
root /vagrant/frontend;
}
}
The uwsgi_params file:
uwsgi_param QUERY_STRING $query_string;
uwsgi_param REQUEST_METHOD $request_method;
uwsgi_param CONTENT_TYPE $content_type;
uwsgi_param CONTENT_LENGTH $content_length;
uwsgi_param REQUEST_URI $request_uri;
uwsgi_param PATH_INFO $document_uri;
uwsgi_param DOCUMENT_ROOT $document_root;
uwsgi_param SERVER_PROTOCOL $server_protocol;
uwsgi_param REQUEST_SCHEME $scheme;
uwsgi_param HTTPS $https if_not_empty;
uwsgi_param REMOTE_ADDR $remote_addr;
uwsgi_param REMOTE_PORT $remote_port;
uwsgi_param SERVER_PORT $server_port;
uwsgi_param SERVER_NAME $server_name;
My Django url pattern:
urlpatterns = [
url(r'^admin/', admin.site.urls),
]
Atm. Im running Django with following command:
uwsgi --socket :8000 --wsgi-file wsgi.py
Im able to reach Django but when I try to access
www.testing.test/api/admin
I get a 404 (debug from Django).
Page not found (404)
Request Method: GET
Request URL: http://www.testing.test/api/admin
Using the URLconf defined in testing.urls, Django tried these URL patterns, in this order:
^admin/
The current URL, api/admin, didn't match any of these.
I know it will be something very simple for people who are used to this stuff, forgive me because Im new.
Ps. I found some similar questions where people worked with
uwsgi_param SCRIPT_NAME /api;
uwsgi_modifier1 30;
But this just made my Django tell me a 404 with
Request URL: http://www.testing.test/api/api/admin
when I requested
Request URL: http://www.testing.test/api/admin