服务器:MySQL5.7,Django2.1,uWSGI,Nginx 我正在处理Django项目,我在一个服务器上部署了Project,在另一台服务器上放置了MySQL。 当我使用django admin更改或添加某些项目时,它非常慢,有时无法获取“更改”页面(Nginx给了我504页),有时无法获取自动完成列表(chrome开发者视图给出了我是504错误)。
我尝试了3种改进方法。 第一个是将两台服务器的Mbps从1 Mbps更改为5 Mbps,这在某些页面上有所帮助。但是并没有解决所有问题。 第二个是更改uWSGI配置,将buffer-size添加为32768。我不确定它是否有帮助,感觉没有帮助。 第三个是更改NGINX配置,我尝试将“ fastcgi_connect_timeout 300”添加到conf文件中,不起作用。 我测试了使用django runserver和使用uwsgi来运行我的项目,它也很慢(〜50s),但是没有504超时错误,所以我认为NGINX配置可能有问题,但是我不知道如何改变。
我的uWSGI.ini代码:
[uwsgi]
socket = 127.0.0.1:9002
chdir = /home/user/project
wsgi-file = project/wsgi.py
master = true
processes = 4
threads = 2
static-map = /static=static
vacuum = true
daemonize = /home/flwang/oncoview/uwsgi.log
py-autoreload = 1
buffer-size 32768 #This is new
我的project_nginx.config代码:
upstream django {
server 127.0.0.1:8000;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
index index.html index.htm index.nginx-debian.html;
access_log /home/user/project/nginx_access.log;
error_log /home/user/project/nginx_error.log;
server_name _;
location /static/ {
alias /home/user/project/static/;
}
location / {
root /home/user/project;
uwsgi_pass django;
include /home/user/project/uwsgi_params;
}
}
NGINX.config代码:
'''
user user;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
'''
期望很简单,至少可以像使用uWSGI一样更改并使其快速。 感谢大伙们。 还有中国春节,新年快乐!
ADD nginx_error日志:
2019/02/12 12:17:20 [error] 5748#5748: *4356 upstream timed out (110:
Connection timed out) while reading response header from upstream, client: 243.14.16.113, server: _, request: "GET /admin/cancer/genev/autocomplete/?term=GATA2%20A4V HTTP/1.1", upstream: "uwsgi://127.0.0.1:9002", host: "www.cancer-know.com", referrer: "http://www.cancer-know.com/admin/cancer/genevdesc/add/"
和uWSGI日志:
[pid: 2273|app: 0|req: 6/181] 243.14.16.113 () {44 vars in 1031 bytes} [Wed Feb
13 15:14:21 2019] GET /admin/cancer/genev/autocomplete/ => generated 871 bytes in 2473 msecs (HTTP/1.1 200) 6 headers in 218 bytes (1 switches on core 1)
[pid: 2684|app: 0|req: 78/182] 243.14.16.113 () {44 vars in 1044 bytes} [Wed Feb 13 15:14:22 2019] GET /admin/cancer/genev/autocomplete/?term=k => generated 829 bytes in 47427 msecs (HTTP/1.1 200) 6 headers in 218 bytes (1 switches on core 0)
[pid: 2688|app: 0|req: 14/183] 243.14.16.113 () {44 vars in 1046 bytes} [Wed Feb 13 15:14:23 2019] GET /admin/cancer/genev/autocomplete/?term=kr => generated 786 bytes in 47209 msecs (HTTP/1.1 200) 6 headers in 218 bytes (1 switches on core 0)
[pid: 2688|app: 0|req: 14/184] 243.14.16.113 () {44 vars in 1050 bytes} [Wed Feb 13 15:14:23 2019] GET /admin/cancer/genev/autocomplete/?term=kras => generated 786 bytes in 48160 msecs (HTTP/1.1 200) 6 headers in 218 bytes (1 switches on core 1)
[pid: 2688|app: 0|req: 78/185] 243.14.16.113 () {44 vars in 1048 bytes} [Wed Feb 13 15:14:23 2019] GET /admin/cancer/genev/autocomplete/?term=kra => generated 786 bytes in 49244 msecs (HTTP/1.1 200) 6 headers in 218 bytes (1 switches on core 1)