nginx+uwsgi+django, there seems to be some strange

2019-05-04 02:10发布

问题:

This is uwsgi config:

[uwsgi]  
uid = 500
listen=200
master = true  
profiler = true 
processes = 8 
logdate = true  
socket = 127.0.0.1:8000  
module = www.wsgi  
pythonpath = /root/www/
pythonpath = /root/www/www 
pidfile = /root/www/www.pid  
daemonize = /root/www/www.log  
enable-threads = true
memory-report = true
limit-as = 6048

This is Nginx config:

server{  
    listen 80;  
    server_name 119.254.35.221;      
    location / {  
        uwsgi_pass 127.0.0.1:8000;  
        include uwsgi_params;  
    }  
}

The django works ok, but modifed pages can't be seen unless i restart uwsgi.(what's more, as i config 8 worker process, i can see the modified page when i press on ctrl+f5 for a while, seems that only certain worker can read and response the modified page, but others just shows the old one, who caches the old page? i didn't config anything about cache)

I didn't config the django, and it works well with "python manager runserver ...", but havfe this problem when working with nginx+uwsgi.

(the nginx and uwsgi are both new installation, i'm sure nothing else is configed here..)

回答1:

  • uwsgi does not reload your code automatically, only development server does
  • runserver is for debug purposes, uwsgi and nginx for production
  • in production you can restart uwsgi by service uwsgi restart or via init.d script
  • there is even better way to reload uwsg by using touch-reload

usually there is no need to cleanup .pyc files, it happens only when timestamps on files are wrong (I've seen it only couple times at my entire carieer)



回答2:

This is normal behavior. uwsgi will not re-read your code unless you restart it (it does not work like runserver when you have DEBUG=True).

If after you have updated your code, restarted uwsgi, cleared your browser cache and it still doesn't reflect your changes, then you should delete *.pyc files from your source directory.

I typically use this:

find . -name "*.pyc" -exec rm {} \;

Roughly speaking, .pyc is the "compiled" version of your code. Python will load this optimized version if it doesn't detect a change in the source. If you delete these files; then it will re-read your source files.