ImageKit does not show thumbnail on Django Admin - django

I have deployed an ubuntu server running Django. For image thumbnailing am using PILLOW and ImageKit. When I try to save an entry the main ImageFile is saved and the thumbnail is created aswell but once I save I get a server error 500. Once I reload the same page the entry loads but shows no thumbnail and once I click on the thumbnail i get a 404 Not found on the browser.
My nginx config is below :
upstream app_server {
server 127.0.0.1:9000 fail_timeout=0;
}
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.html index.htm;
client_max_body_size 4G;
server_name _;
keepalive_timeout 5;
# Your Django project's media files - amend as required
location /media {
alias /home/django/django_project/media;
}
# your Django project's static files - amend as required
location /static {
alias /home/django/django_project/static;
}
# Proxy the static assests for the Django Admin panel
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server;
}
}
The media files ares served correctly. My question now is, shall i create another variable that points to the thumbnail path? Any ideas?
Error listed Below :
IOError at /admin/profiles/districtheatingreference/
decoder jpeg not available
Request Method: GET
Request URL: http://178.62.67.237/admin/profiles/districtheatingreference/
Django Version: 1.7.2
Exception Type: IOError
Exception Value:
decoder jpeg not available
Exception Location: /usr/local/lib/python2.7/dist-packages/PIL/Image.py in _getdecoder, line 419
Python Executable: /usr/bin/python
Python Version: 2.7.6
Python Path:
['/home/django/django_project',
'/home/django',
'/usr/bin',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages']
Server time: Tue, 5 May 2015 10:37:20 +0000
Error during template rendering
In template /usr/local/lib/python2.7/dist-packages/imagekit/templates/imagekit/admin/thumbnail.html, error at line 1
decoder jpeg not available
1 {% if thumbnail %}
2 <a href="{{ model.get_absolute_url|default:original_image.url }}">
3 <img src="{{ thumbnail.url }}">
4 </a>
5 {% endif %}
NGINX LOG :
2015/05/05 06:01:43 [error] 1185#0: *1565 open() "/home/django/django_project/media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_reEvISt/66ad91e0b184febc1b8b71d00e67bff0.JPG" failed (2: No such file or directory), client: 81.143.88.153, server: _, request: "GET /media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_reEvISt/66ad91e0b184febc1b8b71d00e67bff0.JPG HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/profiles/residentialreference/"
2015/05/05 06:01:43 [error] 1185#0: *1578 open() "/home/django/django_project/media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_reEvISt/66ad91e0b184febc1b8b71d00e67bff0.JPG" failed (2: No such file or directory), client: 81.143.88.153, server: _, request: "GET /media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_reEvISt/66ad91e0b184febc1b8b71d00e67bff0.JPG HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/profiles/residentialreference/"
2015/05/05 06:01:43 [error] 1185#0: *1577 open() "/home/django/django_project/media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_reEvISt/66ad91e0b184febc1b8b71d00e67bff0.JPG" failed (2: No such file or directory), client: 81.143.88.153, server: _, request: "GET /media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_reEvISt/66ad91e0b184febc1b8b71d00e67bff0.JPG HTTP/1.1", host: "178.62.67.237"
2015/05/05 06:01:45 [error] 1185#0: *1577 open() "/home/django/django_project/media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_reEvISt/66ad91e0b184febc1b8b71d00e67bff0.JPG" failed (2: No such file or directory), client: 81.143.88.153, server: _, request: "GET /media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_reEvISt/66ad91e0b184febc1b8b71d00e67bff0.JPG HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/profiles/residentialreference/"
2015/05/05 06:01:56 [error] 1185#0: *1583 open() "/home/django/django_project/media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_reEvISt/66ad91e0b184febc1b8b71d00e67bff0.JPG" failed (2: No such file or directory), client: 81.143.88.153, server: _, request: "GET /media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_reEvISt/66ad91e0b184febc1b8b71d00e67bff0.JPG HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/profiles/residentialreference/"
2015/05/05 06:02:02 [error] 1185#0: *1585 open() "/home/django/django_project/media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_reEvISt/66ad91e0b184febc1b8b71d00e67bff0.JPG" failed (2: No such file or directory), client: 81.143.88.153, server: _, request: "GET /media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_reEvISt/66ad91e0b184febc1b8b71d00e67bff0.JPG HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/profiles/residentialreference/"
2015/05/05 06:02:02 [error] 1185#0: *1584 open() "/home/django/django_project/media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_reEvISt/66ad91e0b184febc1b8b71d00e67bff0.JPG" failed (2: No such file or directory), client: 81.143.88.153, server: _, request: "GET /media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_reEvISt/66ad91e0b184febc1b8b71d00e67bff0.JPG HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/profiles/residentialreference/"
2015/05/05 06:02:02 [error] 1185#0: *1584 open() "/home/django/django_project/media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_reEvISt/66ad91e0b184febc1b8b71d00e67bff0.JPG" failed (2: No such file or directory), client: 81.143.88.153, server: _, request: "GET /media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_reEvISt/66ad91e0b184febc1b8b71d00e67bff0.JPG HTTP/1.1", host: "178.62.67.237"
2015/05/05 06:02:06 [error] 1185#0: *1584 open() "/home/django/django_project/media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_reEvISt/66ad91e0b184febc1b8b71d00e67bff0.JPG" failed (2: No such file or directory), client: 81.143.88.153, server: _, request: "GET /media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_reEvISt/66ad91e0b184febc1b8b71d00e67bff0.JPG HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/profiles/residentialreference/"
2015/05/05 06:03:31 [error] 1185#0: *1590 open() "/home/django/django_project/media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_reEvISt/66ad91e0b184febc1b8b71d00e67bff0.JPG" failed (2: No such file or directory), client: 81.143.88.153, server: _, request: "GET /media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_reEvISt/66ad91e0b184febc1b8b71d00e67bff0.JPG HTTP/1.1", host: "178.62.67.237"
2015/05/05 06:03:36 [error] 1185#0: *1590 open() "/home/django/django_project/media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_reEvISt/66ad91e0b184febc1b8b71d00e67bff0.JPG" failed (2: No such file or directory), client: 81.143.88.153, server: _, request: "GET /media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_reEvISt/66ad91e0b184febc1b8b71d00e67bff0.JPG HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/profiles/residentialreference/"
2015/05/05 06:11:21 [error] 1185#0: *1603 open() "/home/django/django_project/media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_reEvISt/66ad91e0b184febc1b8b71d00e67bff0.JPG" failed (2: No such file or directory), client: 81.143.88.153, server: _, request: "GET /media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_reEvISt/66ad91e0b184febc1b8b71d00e67bff0.JPG HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/profiles/residentialreference/"
2015/05/05 06:11:25 [error] 1185#0: *1598 open() "/home/django/django_project/media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_reEvISt/66ad91e0b184febc1b8b71d00e67bff0.JPG" failed (2: No such file or directory), client: 81.143.88.153, server: _, request: "GET /media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_reEvISt/66ad91e0b184febc1b8b71d00e67bff0.JPG HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/profiles/residentialreference/"
2015/05/05 06:11:25 [error] 1185#0: *1603 open() "/home/django/django_project/media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_reEvISt/66ad91e0b184febc1b8b71d00e67bff0.JPG" failed (2: No such file or directory), client: 81.143.88.153, server: _, request: "GET /media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_reEvISt/66ad91e0b184febc1b8b71d00e67bff0.JPG HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/profiles/residentialreference/"
2015/05/05 06:11:25 [error] 1185#0: *1603 open() "/home/django/django_project/media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_reEvISt/66ad91e0b184febc1b8b71d00e67bff0.JPG" failed (2: No such file or directory), client: 81.143.88.153, server: _, request: "GET /media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_reEvISt/66ad91e0b184febc1b8b71d00e67bff0.JPG HTTP/1.1", host: "178.62.67.237"
2015/05/05 06:12:31 [error] 1185#0: *1625 open() "/home/django/django_project/media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_cyxxLNn/fe87a38155418f621c48de1937234bdd.JPG" failed (2: No such file or directory), client: 81.143.88.153, server: _, request: "GET /media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_cyxxLNn/fe87a38155418f621c48de1937234bdd.JPG HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/profiles/residentialreference/"
2015/05/05 06:12:31 [error] 1185#0: *1624 open() "/home/django/django_project/media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_cyxxLNn/fe87a38155418f621c48de1937234bdd.JPG" failed (2: No such file or directory), client: 81.143.88.153, server: _, request: "GET /media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_cyxxLNn/fe87a38155418f621c48de1937234bdd.JPG HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/profiles/residentialreference/"
2015/05/05 06:12:31 [error] 1185#0: *1624 open() "/home/django/django_project/media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_cyxxLNn/fe87a38155418f621c48de1937234bdd.JPG" failed (2: No such file or directory), client: 81.143.88.153, server: _, request: "GET /media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_cyxxLNn/fe87a38155418f621c48de1937234bdd.JPG HTTP/1.1", host: "178.62.67.237"
2015/05/05 06:12:33 [error] 1185#0: *1624 open() "/home/django/django_project/media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_cyxxLNn/fe87a38155418f621c48de1937234bdd.JPG" failed (2: No such file or directory), client: 81.143.88.153, server: _, request: "GET /media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_cyxxLNn/fe87a38155418f621c48de1937234bdd.JPG HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/profiles/residentialreference/"
2015/05/05 06:22:42 [error] 1185#0: *1656 open() "/home/django/django_project/media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_xgGCGrG/9b80392126e96993a428384064177ef4.JPG" failed (2: No such file or directory), client: 81.143.88.153, server: _, request: "GET /media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_xgGCGrG/9b80392126e96993a428384064177ef4.JPG HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/profiles/residentialreference/"
2015/05/05 06:22:42 [error] 1185#0: *1658 open() "/home/django/django_project/media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_xgGCGrG/9b80392126e96993a428384064177ef4.JPG" failed (2: No such file or directory), client: 81.143.88.153, server: _, request: "GET /media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_xgGCGrG/9b80392126e96993a428384064177ef4.JPG HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/profiles/residentialreference/"
2015/05/05 06:22:43 [error] 1185#0: *1652 open() "/home/django/django_project/media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_xgGCGrG/9b80392126e96993a428384064177ef4.JPG" failed (2: No such file or directory), client: 81.143.88.153, server: _, request: "GET /media/CACHE/images/images/ShanRoberts_NWales_Vitocal300A_xgGCGrG/9b80392126e96993a428384064177ef4.JPG HTTP/1.1", host: "178.62.67.237"

Solution found. I was missing some libraries.
apt-get install libjpeg-dev and reinstalling pillow fixed the error!

Related

Configuring Gunicorn with nginx - nginx displaying 500 Internal Server Error when running on port 8000

I'm having issues while setting up nginx and Gunicorn on my local computer (not the server). I have a Django project and I want to be able to access it via http://localhost:8000/. Before my nginx was functional, my Gunicorn server was able to start successfully. However, once I got my nginx server configured, now my Gunicorn server won't start because nginx is already running on my localhost on port 8000. When I visit http://localhost:8000/ I get 500 - Internal Server Error. When I visit http://localhost:80/, however, I get Welcome to nginx! web page.
To configure nginx and Gunicorn, I followed this guide, skipping steps 5 to 7 (inclusive). I have to note that in my /etc/nginx the sites-available and sites-enabled directories didn't exist, so I had to make them.
I have only two files in my /etc/nginx/sites-available directory - default and mydjangoproject. Both have the same contents and both have their symbolic links in /etc/nginx/sites-enabled. Their contents are:
server {
listen 8000;
server_name 127.0.0.1;
location = /favicon.ico { access_log off; log_not_found off; }
location /production_static/ {
root /home/john/Documents/Django_projects/mydjangoproject/Version_2/mydjangoproject;
}
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://127.0.0.1:8000;
}
}
Here are the relevant parts of my Django project's settings.py file:
DEBUG = False
ALLOWED_HOSTS = ['*', '127.0.0.1', 'localhost']
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'production_static/')
MEDIA_ROOT = os.path.join(BASE_DIR,'media')
MEDIA_URL = '/media/'
STATICFILES_DIRS = [
BASE_DIR / "static",
]
Here is the error log from /var/log/nginx/error.log:
2020/12/20 11:58:09 [emerg] 23584#23584: open() "/etc/nginx/proxy_params" failed (2: No such file or directory) in /etc/nginx/sites-enabled/mydjangoproject:11
2020/12/20 12:01:59 [emerg] 23773#23773: open() "/etc/nginx/proxy_params" failed (2: No such file or directory) in /etc/nginx/sites-enabled/mydjangoproject:11
2020/12/20 12:02:04 [emerg] 23775#23775: open() "/etc/nginx/proxy_params" failed (2: No such file or directory) in /etc/nginx/sites-enabled/mydjangoproject:11
2020/12/20 12:02:05 [emerg] 23777#23777: open() "/etc/nginx/proxy_params" failed (2: No such file or directory) in /etc/nginx/sites-enabled/mydjangoproject:11
2020/12/20 12:12:25 [error] 22879#22879: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 127.0.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "127.0.0.1"
2020/12/20 13:51:08 [error] 22879#22879: *3 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 127.0.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "localhost"
2020/12/20 13:55:01 [error] 25938#25938: *1 "/etc/nginx/html/index.html" is not found (2: No such file or directory), client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8000"
2020/12/20 13:55:01 [error] 25938#25938: *1 open() "/etc/nginx/html/favicon.ico" failed (2: No such file or directory), client: 127.0.0.1, server: , request: "GET /favicon.ico HTTP/1.1", host: "localhost:8000"
2020/12/20 13:55:04 [error] 25938#25938: *1 "/etc/nginx/html/index.html" is not found (2: No such file or directory), client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8000"
2020/12/20 13:55:21 [error] 25938#25938: *1 "/etc/nginx/html/index.html" is not found (2: No such file or directory), client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8000"
2020/12/20 13:55:21 [error] 25938#25938: *1 "/etc/nginx/html/index.html" is not found (2: No such file or directory), client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8000"
2020/12/20 13:55:22 [error] 25938#25938: *1 "/etc/nginx/html/index.html" is not found (2: No such file or directory), client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8000"
2020/12/20 13:55:23 [error] 25938#25938: *1 "/etc/nginx/html/index.html" is not found (2: No such file or directory), client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8000"
2020/12/20 13:56:00 [error] 25938#25938: *1 "/etc/nginx/html/index.html" is not found (2: No such file or directory), client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8000"
2020/12/20 13:56:48 [warn] 25999#25999: conflicting server name "127.0.0.1" on 0.0.0.0:8000, ignored
2020/12/20 13:57:11 [warn] 26011#26011: conflicting server name "127.0.0.1" on 0.0.0.0:8000, ignored
2020/12/20 13:57:14 [alert] 26013#26013: *1013 socket() failed (24: Too many open files) while connecting to upstream, client: 127.0.0.1, server: 127.0.0.1, request: "GET / HTTP/1.0", upstream: "http://127.0.0.1:8000/", host: "localhost:8000"
2020/12/20 13:57:15 [alert] 26013#26013: *2025 socket() failed (24: Too many open files) while connecting to upstream, client: 127.0.0.1, server: 127.0.0.1, request: "GET / HTTP/1.0", upstream: "http://127.0.0.1:8000/", host: "localhost:8000"
2020/12/20 13:57:16 [alert] 26013#26013: *3037 socket() failed (24: Too many open files) while connecting to upstream, client: 127.0.0.1, server: 127.0.0.1, request: "GET / HTTP/1.0", upstream: "http://127.0.0.1:8000/", host: "localhost:8000"
2020/12/20 13:57:31 [alert] 26013#26013: *4050 socket() failed (24: Too many open files) while connecting to upstream, client: 127.0.0.1, server: 127.0.0.1, request: "GET / HTTP/1.0", upstream: "http://127.0.0.1:8000/", host: "localhost:8000"
2020/12/20 14:01:02 [alert] 26013#26013: *5064 socket() failed (24: Too many open files) while connecting to upstream, client: 127.0.0.1, server: 127.0.0.1, request: "GET / HTTP/1.0", upstream: "http://127.0.0.1:8000/", host: "localhost:8000"
2020/12/20 14:01:04 [alert] 26013#26013: *6076 socket() failed (24: Too many open files) while connecting to upstream, client: 127.0.0.1, server: 127.0.0.1, request: "GET / HTTP/1.0", upstream: "http://127.0.0.1:8000/", host: "localhost:8000"
I Googled these errors, but came up with nothing. Can someone tell me why is my nginx displaying 500 - Internal server error and how can I get both Gunicorn and nginx to run on the same address and port (if that's even possible)?
As #iklinac mentions, you cant have two ports config to the same id. The port should be 80 like in the tutorial you mentioned. Not 8000 as you have in the original post.
server {
listen 80;
server_name server_domain_or_IP;
}

Error 502 with conflicting server name and (2: No such file or directory)

Mywebsite.co.uk displays a 502 Error. Running sudo tail -F /var/log/nginx/error.log outputs:
2020/10/22 09:42:13 [warn] 200096#200096: conflicting server name "mywebsite.co.uk" on 0.0.0.0:80, ignored
2020/10/22 09:42:13 [warn] 200107#200107: conflicting server name "mywebsite.co.uk" on 0.0.0.0:80, ignored
2020/10/22 09:42:29 [error] 200110#200110: *1 open() "/home/user/mywebsite-app/static/admin/css/fonts.css" failed (2: No such file or directory), client: 37.70.203.239, server: mywebsite.co.uk, request: "GET /static/admin/css/fonts.css HTTP/1.1", host: "mywebsite.co.uk", referrer: "http://mywebsite.co.uk/"
2020/10/22 09:42:50 [crit] 200110#200110: *4 connect() to unix:/home/django/gunicorn.socket failed (2: No such file or directory) while connecting to upstream, client: 37.70.203.239, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/", host: "xxx.xx.xxx.xxx"
2020/10/22 09:42:51 [crit] 200110#200110: *4 connect() to unix:/home/django/gunicorn.socket failed (2: No such file or directory) while connecting to upstream, client: 37.70.203.239, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/", host: "xxx.xx.xxx.xxx"
2020/10/22 09:43:00 [error] 200110#200110: *1 open() "/home/user/mywebsite-app/static/admin/css/fonts.css" failed (2: No such file or directory), client: 37.70.203.239, server: mywebsite.co.uk, request: "GET /static/admin/css/fonts.css HTTP/1.1", host: "mywebsite.co.uk", referrer: "http://mywebsite.co.uk/"
2020/10/22 09:43:24 [error] 200110#200110: *1 open() "/home/user/mywebsite-app/static/admin/css/fonts.css" failed (2: No such file or directory), client: 37.70.203.239, server: mywebsite.co.uk, request: "GET /static/admin/css/fonts.css HTTP/1.1", host: "mywebsite.co.uk", referrer: "http://mywebsite.co.uk/"
2020/10/22 09:57:01 [crit] 200110#200110: *10 connect() to unix:/home/django/gunicorn.socket failed (2: No such file or directory) while connecting to upstream, client: 103.42.252.150, server: _, request: "GET / HTTP/1.0", upstream: "http://unix:/home/django/gunicorn.socket:/", host: "xxx.xx.xxx.xxx:80"
2020/10/22 10:07:00 [error] 200110#200110: *12 open() "/home/user/mywebsite-app/static/admin/css/fonts.css" failed (2: No such file or directory), client: 37.70.203.239, server: mywebsite.co.uk, request: "GET /static/admin/css/fonts.css HTTP/1.1", host: "mywebsite.co.uk", referrer: "http://mywebsite.co.uk/"
2020/10/22 10:07:28 [crit] 200110#200110: *15 connect() to unix:/home/django/gunicorn.socket failed (2: No such file or directory) while connecting to upstream, client: 37.70.203.239, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/", host: "xxx.xx.xxx.xxx"
I suppose it might have somethint to do with gunicorn.socket being in /etc/systemd/system/gunicorn.socket and not at unix:/home/django/gunicorn.socket? Where do I need to change this? What else might be the problem?
My gunicorn.socket:
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=user
Group=user
EnvironmentFile=/home/user/mywebsite-app/env
WorkingDirectory=/home/user/mywebsite-app
ExecStart=/home/user/env/bin/gunicorn \
--access-logfile - \
--workers 3 \
--bind unix:/run/gunicorn.sock \
mywebsite-app.wsgi:application
[Install]
WantedBy=multi-user.target
use unix:/run/gunicorn.sock in upstream or proxy_pass not your unix:/home/django/gunicorn.socket

AWS elasticbeanstalk with django isn't Working

]
I've never used an AWS Beanstalk before, and I get this error, and when I actually get to the address, the "502 badgateway" error is executed how can I solve this problem?(I'm using django)
Edit
I also downloaded the log and those are the errors
eb_engine.log
2020/07/13 02:49:45.963964 [ERROR] /usr/bin/id: healthd: no such user
2020/07/13 02:49:46.338947 [ERROR] Created symlink from /etc/systemd/system/multi-user.target.wants/healthd.service to /etc/systemd/system/healthd.service.
2020/07/13 02:49:46.746061 [ERROR] Created symlink from /etc/systemd/system/multi-user.target.wants/cfn-hup.service to
/etc/systemd/system/cfn-hup.service.
2020/07/13 02:50:26.754823 [ERROR] Creating a Pipfile for this project…
Requirements file provided! Importing into Pipfile…
2020/07/13 02:50:28.038589 [ERROR] Created symlink from /etc/systemd/system/multi-user.target.wants/eb-app.target to /etc/systemd/system/eb-app.target.
2020/07/13 02:50:28.121446 [ERROR] Created symlink from /etc/systemd/system/multi-user.target.wants/web.service to /etc/systemd/system/web.service.
2020/07/13 02:50:28.171612 [ERROR] nginx: the configuration file /var/proxy/staging/nginx/nginx.conf syntax is ok
nginx error
2020/07/13 03:00:43 [error] 3758#0: *140 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.46.96, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "52.79.129.169"
2020/07/13 03:02:41 [error] 3758#0: *162 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.10.51, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "13.209.157.1"
2020/07/13 03:15:07 [error] 3758#0: *347 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.46.96, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "www.sewontax.com"
2020/07/13 03:15:08 [error] 3758#0: *347 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.46.96, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "www.sewontax.com"
2020/07/13 03:15:08 [error] 3758#0: *347 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.46.96, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "www.sewontax.com"
2020/07/13 03:15:08 [error] 3758#0: *347 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.46.96, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "www.sewontax.com"
2020/07/13 03:15:08 [error] 3758#0: *347 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.46.96, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "www.sewontax.com"
2020/07/13 03:15:08 [error] 3758#0: *347 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.46.96, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "www.sewontax.com"
2020/07/13 03:15:09 [error] 3758#0: *347 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.46.96, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "www.sewontax.com"
daemon
error (Invalid timestamp): {:id=>"0", :namespace=>"application", :timestamp=>1594609370, :data=>"{\"duration\":10,\"latency_histogram\":[[0.0,1]],\"http_counters\":{\"status_502\":1,\"request_count\":1}}"}

502 Bad gateway nginx with gunicorn & django

I'm deploying django project using gunicorn and nginx. My nginx setting is,
server {
listen 8000;
server_name 0.0.0.0;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/gagan/saporawebapp;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/gagan/saporawebapp/saporawebapp.sock;
}
}
when i run
sudo nginx -t
It shows that setup is correct . Then i started gunicorn using
gunicorn --daemon --workers 3 --bind unix:/home/gagan/saporawebapp/saporawebapp.sock saporawebapp.wsgi
Then nginx is showing 502 bad gateway. Corresponding error log is,
2019/10/08 07:51:34 [emerg] 3988#3988: open() "/etc/nginx/sites-enabled/saporawebapp" failed (2: No such file or directory) in /etc/nginx/nginx.conf:62
2019/10/08 07:59:54 [crit] 4278#4278: *1 connect() to unix:/home/ubuntu/myproject/myproject.sock failed (2: No such file or directory) while connecting to upstream, client: 42.108.169.252, server: 0.0.0.0, request: "GET /signup/ HTTP/1.1", upstream: "http://unix:/home/ubuntu/myproject/myproject.sock:/signup/", host: "157.245.108.160:8000"
2019/10/08 08:05:19 [crit] 4278#4278: *5 connect() to unix:/home/ubuntu/myproject/myproject.sock failed (2: No such file or directory) while connecting to upstream, client: 42.108.169.252, server: 0.0.0.0, request: "GET /signup/ HTTP/1.1", upstream: "http://unix:/home/ubuntu/myproject/myproject.sock:/signup/", host: "157.245.108.160:8000"
2019/10/08 08:06:24 [crit] 4744#4744: *1 connect() to unix:/home/ubuntu/myproject/myproject.sock failed (2: No such file or directory) while connecting to upstream, client: 42.108.169.252, server: 0.0.0.0, request: "GET /signup/ HTTP/1.1", upstream: "http://unix:/home/ubuntu/myproject/myproject.sock:/signup/", host: "157.245.108.160:8000"
2019/10/08 08:14:47 [alert] 5279#5279: 768 worker_connections are not enough
2019/10/08 08:14:47 [error] 5279#5279: *763 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 157.245.108.160, server: 0.0.0.0, request: "GET /signup/ HTTP/1.0", upstream: "http://157.245.108.160:8000/signup/", host: "157.245.108.160:8000"
2019/10/08 09:49:53 [crit] 11601#11601: *1 connect() to unix:/home/gagan/saporawebapp/saporawebapp.sock failed (2: No such file or directory) while connecting to upstream, client: 42.108.169.252, server: 0.0.0.0, request: "GET / HTTP/1.1", upstream: "http://unix:/home/gagan/saporawebapp/saporawebapp.sock:/", host: "157.245.108.160:8000"

Why is my Springboot deployment to EBS not working?

I am trying to deploy a small SpringBoot application to EBS. I think I have done everything right, including setting up an RDS database, but the deployment fails and I get an error with health degraded as : Following services are not running: application-web-1.
My variables are setup as follows
GRADLE_HOME
/usr/local/gradle
JAVA_HOME
/usr/lib/jvm/java
M2
/usr/local/apache-maven/bin
M2_HOME
/usr/local/apache-maven
SERVER_PORT
5000
SPRING_DATASOURCE_PASSWORD
***
SPRING_DATASOURCE_URL
jdbc:mysql://***.us-east-2.rds.amazonaws.com/ebdb
SPRING_DATASOURCE_USERNAME
***
SPRING_JPA_DATABASE_PLATFORM
org.hibernate.dialect.MySQL5Dialect
SPRING_JPA_HIBERNATE_DDL_AUTO
***
SPRING_PROFILES_ACTIVE
prod
Any advice on how to debug?
My logs below:
-------------------------------------
/var/log/nginx/error.log
-------------------------------------
2019/03/17 19:02:16 [error] 4817#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 82.29.139.73, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com"
2019/03/17 19:02:17 [error] 4817#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 82.29.139.73, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com", referrer: "http://ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com/"
2019/03/17 19:02:25 [error] 4817#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 82.29.139.73, server: , request: "GET /links/ HTTP/1.1", upstream: "http://127.0.0.1:5000/links/", host: "ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com"
2019/03/17 19:02:26 [error] 4817#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 82.29.139.73, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com", referrer: "http://ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com/links/"
2019/03/17 19:57:28 [error] 4817#0: *7 connect() failed (111: Connection refused) while connecting to upstream, client: 178.73.215.171, server: , request: "GET / HTTP/1.0", upstream: "http://127.0.0.1:5000/"
2019/03/17 20:53:11 [error] 4817#0: *9 connect() failed (111: Connection refused) while connecting to upstream, client: 104.152.52.21, server: , request: "GET / HTTP/1.0", upstream: "http://127.0.0.1:5000/"
2019/03/17 20:57:57 [error] 4817#0: *11 connect() failed (111: Connection refused) while connecting to upstream, client: 151.229.68.196, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com"
2019/03/17 20:57:58 [error] 4817#0: *11 connect() failed (111: Connection refused) while connecting to upstream, client: 151.229.68.196, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com", referrer: "http://ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com/"
2019/03/17 21:06:08 [error] 29457#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 151.229.68.196, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com"
2019/03/17 21:06:08 [error] 29457#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 151.229.68.196, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com", referrer: "http://ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com/"
2019/03/17 21:15:47 [error] 30143#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 151.229.68.196, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com"
2019/03/17 21:15:48 [error] 30143#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 151.229.68.196, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com", referrer: "http://ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com/"
2019/03/17 21:15:54 [error] 30143#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 151.229.68.196, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com"
2019/03/17 21:15:54 [error] 30143#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 151.229.68.196, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com", referrer: "http://ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com/"
2019/03/17 21:25:28 [error] 30981#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 151.229.68.196, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com"
2019/03/17 21:25:28 [error] 30981#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 151.229.68.196, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com", referrer: "http://ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com/"
2019/03/17 21:29:36 [error] 31520#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 151.229.68.196, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com"
2019/03/17 21:29:36 [error] 31520#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 151.229.68.196, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com", referrer: "http://ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com/"
2019/03/17 21:34:37 [error] 31520#0: *5 connect() failed (111: Connection refused) while connecting to upstream, client: 151.229.68.196, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com"
2019/03/17 21:34:37 [error] 31520#0: *5 connect() failed (111: Connection refused) while connecting to upstream, client: 151.229.68.196, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com", referrer: "http://ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com/"
Hey I'm not sure if this will work for you, but this is how I solved the
Following services are not running: application-web-1.
issue. I ssh'd onto my elastic beanstalk instance and cd'd to the /var/log directory. I noticed that there was a
web-1.error.log
log showing. I vi'd that log file and there was the exception that was causing the deployment to fail. A txt file that was nested inside a folder within my resources folder was not visible and the following exception was being thrown.
Caused by: java.io.FileNotFoundException: URL [jar:file:/var/app/current/application.jar!/BOOT-INF/classes!/vegetables/vegetables.txt] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/var/app/current/application.jar!/BOOT-INF/classes!/vegetables/vegetables.txt
This occurred because I was using PathMatchingResourcePatternResolver to get the resources, then traversing the resources by filename, and directly trying to access the file by using resource.getFile(). Instead of getting the data by the file. I used
byte[] dataArr = FileCopyUtils.copyToByteArray(resource.getInputStream());
and that allowed me to use the data in the byte array the same way I used it by accessing the file directly. I hope this helps.