How to update css/scss files with NGINX - django

I am running a Digital Ocean droplet with Gunicorn and NGINX. I am able
to view my web pages but I am not able to update html/css/scss.
I have added include /etc/nginx/mime.types; in /etc/nginx/nginx.conf as suggested in another post. Also tried
python manage.py collectstatic and received the following: 0 static files copied to '/home/ubuntuadmin/pyapps/nomad/static', 177 unmodified
sudo nano /etc/nginx/sites-available/nomad >>>
server {
listen 80;
server_name 157.245.0.153;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/ubuntuadmin/pyapps/nomad;
}
location /media/ {
root /home/ubuntuadmin/pyapps/nomad/;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
include /etc/nginx/mime.types;
}
}```

Related

Getting 504 Gateway Time-out nginx/1.18.0 (Ubuntu) in django nginx

I am facing problems launching my django app in digitalocean. I have done all the needful but I am quite sure I made error some where. Below is my nginx configuration file. What could be the problem . Thanks alot .
PLease I would also love to know how to access nginx error log file through command line.
server {
server_name server_Ip;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/username/myproject/smsdigo;
}
location /media/ {
root /home/username/myproject/smsdigo;
}
location /locale/ {
root /home/ebong/myproject/smsdigo;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
server {
listen 80;
client_max_body_size 3000M;
client_body_buffer_size 3000M;
client_body_timeout 120;
}
Problably you need increase fastcgi timeout directives:
Try 60s or more. For example:
server{
fastcgi_read_timeout 60s;
fastcgi_send_timeout 60s;
}

Django Nginx Media Folder for User Upload/Download

As part of an app I am working on with Django DRF and Vue, I have a section for uploading and downloading files. Files get uploaded to a media folder and are displayed as a list where users can download them. This all works fine in development running 'python manage.py run server' and 'npm run serve' but I am getting mixed results deploying it on Nginx with Docker.
I have tried every configuration possible. Currently, uploading and showing as a list is working without issue. When trying to download the files I am getting a 404 not found error. It is using the correct URL: "[website]/media/[file]". When looking in my Docker folder directory, the file exists at the specified path, so I am not sure what is going on.
This is the server configuration I believe may need to be adjusted.
server {
listen 443 ssl;
server_name [website].com www.[website].com;
root /dist/;
index index.html;
ssl_certificate /etc/letsencrypt/live/keeptrackapp.ca/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/keeptrackapp.ca/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
# backend urls
location ~ ^/(admin|api|accounts|media|registration|auth|api-auth) {
proxy_redirect off;
proxy_pass http://backend;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}
location = /robots.txt { log_not_found off; }
location = /sitemap.xml { log_not_found off; }
location = /favicon.ico { log_not_found off; }
location /media {
alias /media;
}
location /static {
alias /app/static;
}
# frontend
location /index.html {
try_files $uri $uri/ #rewrites;
}
location #rewrites {
rewrite ^(.+)$ /index.html last;
}
}
I have tried a few different variations for the media location including...
location /media {
alias /media;
}
location /media/ {
alias /media/;
}
location /media {
root /media;
}
location /media/ {
root /media/;
}
location ^~ /media {
root /media;
}
This is not an extensive list. I have tried every variation I could think of. Please provide some insight if I am approaching this wrong.
Cheers.

Nginx location doesnt workd

I have a Django app running with Nginx and Gunicorn on mysite.com. I would like it to be accessible only under mysite.com/myapp. This is my nginx configuration:
server {
listen 80;
server_name server_domain_or_IP;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/sammy/myprojectdir;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
When I change location / to location /myapp/, I get "Not found error". Nginx error log doesn't seems to have anything. What could be the issue?

How to make Nginx config file for Django Project?

I made Nginx config for My Django project.
For DNS I associate with my IP.
But this config not working, when I'm checking xyz.com in web but getting error ERR_CONNECTION_REFUSED.
server {
listen 80;
server_name xyz.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/ubuntu/project;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/ubuntu/project/project.sock;
}
}
Please correct me if i'm doing wrong.

Nginx unable to load static files from django

family, Im having a little trouble to make nginx server load static file collected by django. here is my nginx sites-available
server {
listen 80;
server_name <my_ip_address>;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
}
location /asset/ {
autoindex on;
alias /var/www/html/dev2_assets/;
}
}
Down here is my Django STATIC_URL and STATIC_ROOT configurations
STATIC_URL = '/assets/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "assets"),
)
STATIC_ROOT = '/var/www/html/dev2_assets/'
When i run the application with ./manage.py runserver its loads all the static files. Any help. Thanks
Your problem is your Location.
Your not specifying a root for it, also in your settings.py your declaring assets but in your location your declaring asset with a missing s. try changing it to something like this:
location /assets/ {
autoindex on;
root /var/www/html/dev2_assets;
}
Also for debugging purposes try added this above location:
error_log /var/log/nginx/error.log;
Then you will get a specific error message about it not being able to retrive your static files.
Lastly are you sure your utilyzing nginx, django, and gunicorn correct?
Here is a copy of my site file for comparison:
# This redirects all incoming traffic on port 80 to 443
server {
listen 80;
server_name domain.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443;
ssl on;
ssl_certificate /etc/ssl/domain.com.chained.crt;
ssl_certificate_key /etc/ssl/domain.com.key;
server_name helius.dk;
access_log /var/log/nginx/nginx.vhost.access.log;
error_log /var/log/nginx/nginx.vhost.error.log;
#location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/user/projectname/static;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/user/projectname/gunicorn.sock;
}
}