Uploading video gets stuck between 40 - 45 % Gunicorn + Nginx + Django - django

Video is 385mb here is my nginx conf
server {
listen 85;
send_timeout 120;
http2_max_field_size 64k;
http2_max_header_size 64k;
client_max_body_size 1000M;
client_body_buffer_size 4096M;
client_body_timeout 350;
client_body_temp_path /home/mrlonely/lumendjango/media;
location = /favicon.ico { access_log off; log_not_found off; }
location /static {
autoindex on;
alias /home/mrlonely/lumendjango/staticfiles;
}
location /media {
client_max_body_size 1000m;
autoindex on;
alias /home/mrlonely/lumendjango/media;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/mrlonely/lumendjango/lumen.sock;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_set_header Host $host;
proxy_redirect off;
proxy_headers_hash_max_size 512;
proxy_headers_hash_bucket_size 128;
proxy_read_timeout 1200;
}
}
It gives me : net::ERR_CONNECTION_CLOSED
Ive tried different things as you can see above, but i dont think the problem is with Nginx or Gunicorn, can't find anything good online. Can someone help me? If you need to see additional info please tell me, I dont know what else to put here.

Related

I can seeimage locally in django It's not visible in the deployment environment. What should I do?

enter image description here
In the development environment, there's no problem
It's being uploaded.
However, if you upload it to the server, you can write a post it.
I can't see the picture.
nginx.conf
worker_processes auto;
events {
}
http {
client_max_body_size 100M;
keepalive_timeout 3000;
server {
listen 80;
client_body_buffer_size 256k;
include mime.types;
location /static/ {
alias /data/static/;
}
location /media/ {
alias /data/media/;
}
client_max_body_size 100M;
location / {
proxy_pass http://django_container_gunicorn:8000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
}
}
}
What should I do?

Nginx Base Auth

I work with Django and Nginx
I added the following entry to my config to restrict access to example.com/admin/
The function asks for a password, and everything works, but after that, as I get a 404 Not Found error from Nginx
Full config
upstream rates_core_server {
server unix:/webapps/example.com_app/example.com/run/gunicorn.sock fail_timeout=0;
}
server {
listen 80;
server_name example.com www.example.com;
client_max_body_size 4G;
access_log /webapps/example.com_app/logs/nginx-access.log;
error_log /webapps/example.com_app/logs/nginx-error.log;
location /admin/ {
auth_basic "Restricted Content";
auth_basic_user_file /etc/nginx/.htpasswd;
}
location /static/ {
alias /webapps/example.com_app/example.com/static/;
client_max_body_size 100M;
}
location /media/ {
alias /webapps/example.com_app/example.com/static/media/;
client_max_body_size 100M;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://example.com_server;
break;
}
}
# Error pages
error_page 500 502 503 504 /500.html;
location = /500.html {
root /webapps/example.com_app/example.com/static/;
}
}
I do not understand what the problem is
With the current config, nginx does not know where to look for or redirect to for admin block. Can you include proxy_pass settings in your admin block as well, like this:
location /admin/ {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://example.com_server;
break;
}
auth_basic "Restricted Content";
auth_basic_user_file /etc/nginx/.htpasswd;
}

Django + Nginx + Gunicorn example.com works but www.example.com returns Bad Request (400)

I'm trying to make it possible to access www.example.com aswell as example.com which works fine but it returns Bad Request 400:
Django:
ALLOWED_HOSTS = ['librestock.com', 'www.librestock.com']
Nginx:
server {
listen 80;
server_name librestock.com www.librestock.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/david/StockSearch/stocksearch;
}
location / {
include proxy_params;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://unix:/home/david/StockSearch/stocksearch/stocksearch.sock;
}
}
any ideas for debugging and troubleshooting this?

Nginx Multiple Domains One App and Server

I want to run multiple websites on the same django app and the same nginx server.
I am successfully running http: //myip/ and http: //myip/name1 and http: //myid/name2
Now I want to link all these projects to myname.com and name1.com and name2.com
How should I change my nginx config file? The current version of the file is shown below. Thanks
upstream crsq {
server localhost:8000;
}
server {
listen 80 default;
access_log /home/ubuntu/crsq-access.log;
error_log /home/ubuntu/crsq-error.log error;
# Make site accessible from http://localhost/
server_name crsq;
location #proxy_to_crsq_app {
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
proxy_set_header X-Forwarded-Port $http_x_forwarded_port;
proxy_set_header X-Forwarded-For $http_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http: //crsq;
}
location /robots.txt {
alias /home/ubuntu/crsq/crsq/robots.txt;
}
location / {
try_files $uri #proxy_to_crsq_app;
}
location /static {
alias /home/ubuntu/crsq/crsq/static;
}
}
upstream crsq {
server localhost:8000;
}
server {
listen 80 ;
access_log /home/ubuntu/crsq-access.log;
error_log /home/ubuntu/crsq-error.log error;
# Make site accessible from http://localhost/
server_name a.b.c;
location #proxy_to_crsq_app {
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
proxy_set_header X-Forwarded-Port $http_x_forwarded_port;
proxy_set_header X-Forwarded-For $http_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http: //crsq;
}
location /robots.txt {
alias /home/ubuntu/crsq/crsq/robots.txt;
}
location / {
try_files $uri #proxy_to_crsq_app;
}
location /static {
alias /home/ubuntu/crsq/crsq/static;
}
}
server {
listen 80 ;
access_log /home/ubuntu/crsq-access.log;
error_log /home/ubuntu/crsq-error.log error;
# Make site accessible from http://localhost/
server_name b.c.d;
location #proxy_to_crsq_app {
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
proxy_set_header X-Forwarded-Port $http_x_forwarded_port;
proxy_set_header X-Forwarded-For $http_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http: //crsq;
}
location /robots.txt {
alias /home/ubuntu/crsq/crsq/robots.txt;
}
location / {
try_files $uri #proxy_to_crsq_app;
}
location /static {
alias /home/ubuntu/crsq/crsq/static;
}
}

Nginx / Django: Accessing static files results in 403 Forbidden

I've been trying to debug this for several hours and I'm not sure what else to check. My problem is that Nginx doesn't server Django static files. Accessing static files results in the error 403 Forbidden.
The exact error from nginx error log is:
2013/02/11 05:42:13 [error] 22526#0: *29 open() "/home/mydomain/public_html/test2/src/bootstrap.css" failed (13: Permission denied), client: XXX.XXX.XX.XX, server: mydomain.com, request: "GET /src/bootstrap.css HTTP/1.1", host: "www.mydomain.com"
Here is my nginx config file:
server {
listen XX.XX.X.XXX:80;
server_name mydomain.com;
root /home/mydomain/public_html/test2/app;
# serve directly - analogous for static/staticfiles
location /media/ {
# if asset versioning is used
if ($query_string) {
expires max;
}
}
location /admin/media/ {
# this changes depending on your python version
root /home/mydomain/public_html/test2/lib/python2.7/site-packages/django/contrib;
}
location /src/ {
autoindex on;
root /home/mydomain/public_html/test2;
}
location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_connect_timeout 10;
proxy_read_timeout 10;
proxy_pass http://localhost:8000/;
}
# what to serve if upstream is not available or crashes
error_page 500 502 503 504 /media/50x.html;
}
Static files are stored in /home/mydomain/public_html/test2/src.
I've tried chown mydomain.mydomain -R * and chmod 755 /home/mydomain -R * without any effect.
use this
btw. IfIsEvil
server {
listen 80;
server_name mydomain.com;
#access_log /var/log/nginx/x_access.log;
#error_log /var/log/nginx/x_error.log;
location /static {
alias /path/to/your/static;
}
location /media {
alias /path/to/your/media;
}
location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_connect_timeout 10;
proxy_read_timeout 10;
proxy_pass http://localhost:8000/;
}
}
Here is a working solution to my initial problem:
server {
listen XX.XX.X.XXX:80;
server_name mydomain.com;
root /home/mydomain/public_html/test2/app;
location /admin/media/ {
# this changes depending on your python version
root /home/mydomain/public_html/test2/lib/python2.7/site-packages/django/contrib;
}
location /src {
root /home/mydomain/public_html/test2;
}
location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_connect_timeout 10;
proxy_read_timeout 10;
proxy_pass http://localhost:8000/;
}
# what to serve if upstream is not available or crashes
error_page 500 502 503 504 /media/50x.html;
}
Another way to do this is to use try_files. The advantage of this is that Nginx will first look for a real file to serve, and if it fails to find one it passes execution to your django app. This is perfect for serving a dynamic sitemap.xml for example since you do not need to special-case the file in nginx.conf.
# Set default expires headers (used for static assets)
expires 30d;
server {
listen 80;
server_name mydomain.com;
root /some/path/assets/;
try_files $uri #django;
location #django {
expires -1d;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
proxy_pass http://unix:/some/path/server.sock;
}
location /static/admin/ {
alias /some/path/lib/python2.7/site-packages/django/contrib/admin/static/admin/;
}
}