【发布时间】:2019-06-09 05:31:31
【问题描述】:
我正在尝试更新一个基于 nginx+Flask+uwsgi 的 Web 项目。当我更新任何 python 文件时,我发现 nginx 仍在使用旧文件。当我删除所有 *.pyc 文件时,python 解释器没有生成新的 pyc 文件。好像有缓存,我按照这个question的回答尝试清除nginx的缓存。但它没有用。
有没有人知道让 nginx 从新的源文件解释 python 的任何解决方案?
这是 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;
}
}
这是另一个配置文件:
(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
【问题讨论】:
-
我认为不是 nginx 的问题——而是烧瓶/uwsgi 的问题。尝试重新启动 flask/uwsgi 服务器 - 然后 nginx 应该提供新文件。
-
我是 Flask 的新手。除了使用 systemctl 重启 nginx,我应该如何重启 flask/uwsgi?
-
这取决于您运行堆栈的方式。可能性很少。一般来说uwsgi server是nging下面的一层。请提供更多信息,您以何种方式运行您的应用程序,而不是我试图提供的帮助。
-
我在问题中粘贴了配置文件。够了吗?
-
我在下面回答 - 如果此解决方案适合您,请告诉我。
标签: python nginx caching flask