0

I'm trying update a web project which based on the nginx+Flask+uwsgi. And when I updated any python files, I found nginx was still using the old ones. When I removed all *.pyc files, no new pyc file was generated by python interpreter. It looks like there is a cache, I followed the answer of this question to try to clear the cache of nginx. But it didn't work.

Does anybody know any solution to let nginx to interpret python from new source file?

This is the nginx.conf

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    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            off;
    #tcp_nopush          on;
    #tcp_nodelay         on;
    keepalive_timeout   65;
    #types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;
    server {
        listen 80;
        server_name m.xxxx.com.cn;
        location / {
            include uwsgi_params;
            uwsgi_pass unix:/root/003_exampleproject/exampleproject.sock;
        }
    }

And this is another config files:

(venv) [root@VM_0_3_centos 003_exampleproject]# cat /etc/systemd/system/exampleproject.service
[Unit]
Description=uWSGI instance to serve exampleproject
After=network.target

[Service]
User=root
Group=nginx
WorkingDirectory=/root/003_exampleproject/
Environment="PATH=/root/003_exampleproject/venv"
ExecStart=/root/003_exampleproject/venv/bin/uwsgi --ini exampleproject.ini --logto /var/log/uwsgi/exampleproject.log

[Install]
WantedBy=multi-user.target

(venv) [root@VM_0_3_centos 003_exampleproject]# cat exampleproject.ini
[uwsgi]
module = manage:app

master = true
processes = 5

socket = exampleproject.sock
chmod-socket = 660
vacuum = true

die-on-term = true
env = MBUS_ADMIN=root@example.com

ZMJ
  • 337
  • 2
  • 11
  • I think is not problem of nginx - but of flask/uwsgi. Try to restart flask/uwsgi server - then nginx should serve new files. – Adam Puza Jan 15 '19 at 08:25
  • I'm new for Flask. How should I restart flask/uwsgi except using systemctl to restart nginx? – ZMJ Jan 15 '19 at 08:44
  • It depends on the way how you are running your stack. There are few possibilities. In general uwsgi server is a layer below nging. Please provide more information what way you are running your app than I try to help. – Adam Puza Jan 15 '19 at 08:53
  • I pasted the config files in the question. Is that enough? – ZMJ Jan 15 '19 at 09:34
  • I answered below - please let me know if this solution works for you. – Adam Puza Jan 15 '19 at 09:47

1 Answers1

0

Short answer:

service exampleproject restart

or

systemctl restart exampleproject.service

Long answer:

Regarding to your config files service that need to be restarted is:

exampleproject.service

If you run command

service --status-all

You should have it listed there.

Then you may use commands:

service exampleproject 

will print allowed commands.

Try then:

service exampleproject restart

Note: service command should work on your centos, but if not work in your distribution you may try to use alternative:

systemctl restart exampleproject.service
Adam Puza
  • 1,504
  • 13
  • 9