Daniel
The Telegram login for your website on Django – Dmytro Striletskyi – Medium https://medium.com/@dmytrostriletskyi/the-telegram-login-for-your-website-on-django-3661f8ac7a2e
Anonymous
So it looks like it stays on memory, like if it's not being stored anywhere.
Anonymous
are u using Gunicorn or some kind of uwsgi?
Yes, I'm using NGINX + Gunicorn + Django + PostgreSQL + Docker.
Anonymous
NGINX and Gunicorn seem to be working.
Anonymous
I can create users, login, etc.
Daniel
Yes, I'm using NGINX + Gunicorn + Django + PostgreSQL + Docker.
because Gunicorn doesn't know where static files are
Daniel
in that case, the issue is in your Nginx configuration file
Anonymous
Maybe django can't access those
Anonymous
Something wrong in config?
Daniel
How To Set Up Django with Postgres, Nginx, and Gunicorn on Debian 8 | DigitalOcean https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-debian-8
Anonymous
because Gunicorn doesn't know where static files are
How can I tell NGINX where they are?
Anonymous
in that case, the issue is in your Nginx configuration file
This is my NGINX configuration: https://gist.github.com/da-edra/99528d8ab9148158ff00e9b73ea20ffe
Anonymous
Maybe django can't access those
You mean a permission problem?
Daniel
How can I tell NGINX where they are?
compare your config file with the one from that tutorial
Anonymous
Yeah, logs are great
Daniel
server { listen 80; server_name server_domain_or_IP; location = /favicon.ico { access_log off; log_not_found off; } location /static/ { root /home/sammy/myproject; } }
Daniel
ahh damn format. Anyway, you didn't include the location directive to your static files
Anonymous
😂
Anonymous
He did though.
Anonymous
Also, but what does location is I don't know about.
Anonymous
You mean this part?
Anonymous
location / { # everything is passed to Gunicorn proxy_pass http://asofarma_server; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; proxy_redirect off; }
Anonymous
location/static/
Anonymous
According to Digital Ocean's tutorial it's like this: location / { include proxy_params; proxy_pass http://unix:/home/sammy/myproject/myproject.sock; }
Anonymous
Yeah, it uses sockets
Anonymous
What are you doing though?
Anonymous
Interesting, so I'm apparently missing a socket?
Anonymous
I'm uploading a pdf from the Django admin.
Anonymous
And then I try to show it on a template.
Anonymous
But I'm unable to access the file.
Anonymous
It depends on how you wanna do it
Anonymous
Could the problem be with Docker?
Anonymous
You probably got static storage messed up
Anonymous
Config*
Anonymous
Did you setup your config yourself or used a tutorial?
Anonymous
I used a tutorial for Docker.
Anonymous
This is my docker-compose.yml
Anonymous
https://gist.github.com/da-edra/82ac5b45b2391ace8e31c98efcbdcc72
Anonymous
And this is how my template looks like after I upload a file: https://imgur.com/a/cJpRDQa
Anonymous
Via the Django admin I can see who posted it, the date, etc.
Anonymous
And it shows in the frontend that it's uploaded.
Anonymous
But when I access it I get the 404.
Anonymous
But when I access it I get the 404.
Can you share your code for uploading
Anonymous
The "view" behind it
Anonymous
I'm uploading it using a models.py
Anonymous
Here it is:
Anonymous
https://gist.github.com/da-edra/8f2cbaa6d5fd42c8bb3705d21d85713a
Anonymous
Is this the right way to do it?
Daniel
But I'm unable to access the file.
in that case it's a permissions issue, make sure the right permissions have been granted on the folder to its rightful owner
Daniel
if you're running as root in the container it's not good
Daniel
you're suppose to have a user with limited privileges aka www-data
Anonymous
This are the permissions: -rw-r--r-- 1 root root 343768 Jul 30 06:02
Anonymous
The user is root. :(
Anonymous
I've added my user to the docker group so I don't need to be using sudo to use Docker.
Anonymous
After changing permissions to 777 the error persists.
Daniel
I've added my user to the docker group so I don't need to be using sudo to use Docker.
that's not related with what's happening inside the container
Anonymous
Also, the file is accessible trough the Gunicorn container but not from the NGINX container.
Daniel
you're going to have to tweak the dockerfile a little to include useradd and permission granting chown on the required dirs
Anonymous
From the logs I see that: nginx_1 | 2018/07/30 06:02:47 [error] 8#8: *3 open() "/opt/services/media/files/2018-07-30/Filename.pdf" failed (2: No such file or directory), client: 172.19.0.1, server: localhost, request: "GET /media/files/2018-07-30/Filename.pdf HTTP/1.1", host: "localhost", referrer: "http://localhost/users/" nginx_1 | 172.19.0.1 - - [30/Jul/2018:06:02:47 +0000] "GET /media/files/2018-07-30/Filename.pdf HTTP/1.1" 404 169 "http://localhost/users/" "Mozilla/5.0 (X11; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0" "-"
Daniel
and then you can add in the docker-compose the declaration user: django-user
Anonymous
did you check if the file exists?
Yes, it does if I access the Gunicorn container but if I do it from the NGINX container the file can't be found.
Daniel
ok
Daniel
then you need to mount that volume on the container that needs the data ( nginx)
Anonymous
Yes, I have 3 containers, one for NGINX, other for Gunicorn, other for PostgreSQL.
Daniel
make a persistent volume and just mount it on nginx
Anonymous
If I find / -name "Filename.pdf" from the NGINX container I get: find: '/proc/8/map_files': Permission denied
Daniel
those are kernel specific directories that are guarded by Kernel's DAC system
Anonymous
I find it interesting that I don't get that error from the Gunicorn volume.
Daniel
what's the absolute path to that PDF?
Daniel
you can search via find /opt/services/media -type f -name '*.pdf'
Daniel
and it will find your PDFs
Anonymous
On the Gunicorn container it finds it as /opt/services/media/files/2018-07-30/Filename.pdf
Anonymous
But it only finds one PDF, the latest one I've uploaded, the other appear to be gone.