I'm trying to make a big request, how to generate a pdf using Django nginx, Here is my nginx.conf:
I think this request is not high.
What can I do to increase this request from the server?
server {
server_name .urbanarts.com.br;
client_max_body_size 10M;
client_body_timeout 10;
client_header_timeout 10;
keepalive_timeout 15;
send_timeout 10;
rewrite ^ https://urbanarts.com.br$request_uri? permanent;
location /static {
autoindex on;
alias /srv/www/urbanarts/project/urbanarts_cloud/app/static;
log_not_found on;
}
location / {
proxy_redirect off;
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_set_header X-Forwarded-Protocol $scheme;
proxy_pass http://127.0.0.1:8007/;
}
location /robots.txt {
root /srv/www/urbanarts/project/urbanarts_cloud/app/static;
access_log off;
log_not_found off;
}
location /favicon.ico {
root /srv/www/urbanarts/project/teste/urbanarts_cloud/static/images;
access_log off;
log_not_found off;
}
}
Thanks..
Do not keep increasing the time out, this is not going to help you in the long run.
Instead, use celery or python-rq to send your long running task to the background and return a response immediately.
Related
I've created a rest API for my Django app but how I go to api.website.com rather than something like www.website.com/api
Btw I'm using nginx if that has to do anything with this
In your nginx configuration add something like this. This passes all requests on api.website.com to your gunicorn socket -> your django app.
server {
listen *:80;
server_name api.website.com;
location ~ ^/api(.*)$ {
try_files $uri $1 /$1;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://gunicorn_socket/;
}
}
I have written two micros services with python and ruby. The python one serves some api requests. and the ruby one serves the other api requests.
the python one listens port 80 and can handle /users /feeds requests
the ruby one listens port 4567 and can handle /orders /products requests.
the following is my config file .but it does not work with nginx .
upstream midgard_api_cluster
{
server unix:/tmp/midgard_api.sock;
}
upstream tradeapi {
server 127.0.0.1:4567;
}
server {
listen 80;
server_name my.domain.name;
client_max_body_size 20M;
set $x_remote_addr $http_x_real_ip;
if ($x_remote_addr = "") {
set $x_remote_addr $remote_addr;
}
access_log /var/log/nginx/midgard/access_log ;
error_log /var/log/nginx/midgard/error_log ;
charset utf-8;
location /static/ {
root /opt/www/templates/;
expires 30d;
}
location / {
error_page 502 503 504 /500.html;
uwsgi_pass midgard_api_cluster;
include uwsgi_params;
# proxy_redirect default;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $x_remote_addr;
proxy_set_header Host $http_host;
proxy_set_header Range $http_range;
proxy_connect_timeout 10;
proxy_send_timeout 10;
proxy_read_timeout 11;
}
location /products {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://tradeapi;
proxy_redirect off;
}
location /orders {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://tradeapi;
proxy_redirect off;
}
}
Now , when i use
curl http://my.domain.name/products
It got a 404 error and the request was directed to the python service .
and
curl http://my.domain.name:3000/products
can get the right response .
How can i setup the nginx configuration file and route the request to the ruby service ?
locations are processed in order. The /-location matches before /products so the later is never reached. Put / at the end of the config file.
I'm trying to bring this supervisord+nginx+tornado setup to work. Since the Tornado-files are reachable via IP:8000 and IP:80 shows me the 'Welcome to nginx' I thought that maybe my nginx.conf contains errors. I aim to let this deliver my tornado-site to the users at port 80.
nginx.conf looks like this:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
use epoll;
}
http {
# Enumerate all the Tornado servers here
upstream frontends {
server 127.0.0.1:8000;
server 127.0.0.1:8001;
server 127.0.0.1:8002;
server 127.0.0.1:8003;
}
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
keepalive_timeout 65;
proxy_read_timeout 200;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
gzip on;
gzip_min_length 1000;
gzip_proxied any;
gzip_types text/plain text/css text/xml
application/x-javascript application/xml
application/atom+xml text/javascript;
# Only retry if there was a communication error, not a timeout
# on the Tornado server (to avoid propagating "queries of death"
# to all frontends)
proxy_next_upstream error;
server {
listen 80;
# Allow file uploads
client_max_body_size 50M;
location static/ {
root /srv/www/url/tornado/;
if ($query_string) {
expires max;
}
}
location = /favicon.ico {
rewrite (.*) /static/favicon.ico;
}
location = /robots.txt {
rewrite (.*) /static/robots.txt;
}
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_pass http://frontends;
}
}
}
help is much appreciated.
This is the supervisord.conf:
[include]
files = *.supervisor
[supervisord]
[supervisorctl]
serverurl = unix://supervisord.sock
[unix_http_server]
file = supervisord.sock
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[program:main]
process_name = main-%(process_num)s
command = python /srv/www/url/tornado/main.py
--port=%(process_num)s
--log_file_prefix=%(here)s/logs/%(program_name)s-%(process_num)s.log
numprocs = 4
numprocs_start = 8000
Wild guess: add a server_name param to nginx config.
Also, what does supervisor say when you start your app?
If it's okay (started), take a look at tornado and nginx logs.
If you provide them here, figuring out the answer would be much easier.:)
I'm trying to set up Tornado server behind nginx proxy, here're the relevant bits of the configuration:
server {
listen 80;
server_name localhost;
location html/ {
root /srv/www/intj.com/html;
index login.html;
if ($query_string) {
expires max;
}
}
location = /favicon.ico {
rewrite (.*) /html/favicon.ico;
}
location = /robots.txt {
rewrite (.*) /html/robots.txt;
}
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_pass http://localhost:8888;
}
}
I can get to my Python server through nginx, but when I request a static pages, such as, say login.html, which is located in /srv/www/intj.com/html/login.html, instead of loading the static file, the request is forwarded to Tornado, which doesn't know what to make of it.
What did I do wrong?
Well, it actually had to be ^~ /html/, but I don't really know what it means / what is the difference, so it would be cool if someone could enlighten me.
Try this and tell me how it goes.
server {
listen 80;
server_name localhost;
location / {
if($query_string) {
root /srv/www/intj.com/html;
index index.html;
try_files $uri $uri/;
}
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_pass http://localhost:8888;
}
}
I have a custom nginx build for my project and everything works fine except I'm confused about serving static files using the same nginx server (below you can see my config file) recently tried to set root=/home/USERNAME/media/app/ and root= /home/USERNAME/.virtualenvs/medialaw; also created static only applications in control panel and pointed extra_info to my MEDIA_ROOT and STATIC_ROOT respectively but all things failed.
Can anyone help me with it, may be someone already faced such a challenge?
server {
listen MY_PORT;
server_name USERNAME.webfactional.com;
access_log /home/USERNAME/logs/user/nginx/app_access.log;
error_log /home/USERNAME/logs/user/nginx/app_error.log;
root /home/USERNAME/.virtualenvs/medialaw;
location /m {
alias /home/USERNAME/media/app/media;
if ($query_string) {
expires max;
}
}
location /s {
alias /home/imanhodjaev/media/app/static;
if ($query_string) {
expires max;
}
}
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:PORT/;
}
error_page 500 502 503 504 /media/50x.html;
}
I've posted this question recently on webfaction Q&A site
http://community.webfaction.com/questions/10535/django-141-serving-static-and-media-with-custom-nginx-build
Thanks,
Sultan
Problem resolved this is how configuration looks like so far
Nginx
server {
listen MY_PORT;
server_name USERNAME.webfactional.com;
access_log /home/USERNAME/logs/user/nginx/app_access.log;
error_log /home/USERNAME/logs/user/nginx/app_error.log;
root /home/USERNAME/media/app;
location /m {
alias /home/USERNAME/media/app/media;
}
location /s/ {
alias /home/imanhodjaev/media/app/static;
}
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:PORT/;
}
error_page 500 502 503 504 /media/50x.html;
}
Webfaction configuration from control panel
Deleted two static only apps filled required fields and set extra_info for static and media locations respectively.
Thanks,
Sultan