Nginx服务器“caching”PHP。 更新页面不重新加载

Nginx似乎caching我的PHP文件 ,因为它服务于同一个PHP页面,即使我改变了服务器上的文件。

我在用:

  • 由Digitalocean发布的Ubuntu 16.04 Droplet
  • nginx / 1.10.0(正常LEMP 一键安装)
  • PHP 7.0.13-0ubuntu0.16.04.1

我尝试了不同的机器,问题依然存在。

我在Apache2上进行了testing,php文件正在按预期更新。 所以我认为问题在于Nginx。

debugging过程:新服务器和新鲜的LEMP安装:

  1. 根据这个网站 , 编辑nginx.confsendfile on改为sendfile off 。 然后用nginx -s reload重新加载nginxconfiguration(参见下面的nginx.conf文件)
  2. test.mypersonalsite.com 创build新的服务器块 (请参阅下面的服务器块文件)
  3. 将服务器块链接sites-enabledsites-enabled目录

sudo ln -s /etc/nginx/sites-available/test.mypersonalsite.com /etc/nginx/sites-enabled/

  1. nginx -t 检查并重新启动nginx ,然后sudo systemctl restart nginx

  2. 创buildindex.htmlindex.php部署到服务器(Works完美)

直到这里一切正常,在这之后它错误

  1. index.htmlindex.php从v1.0.7更新到v1.0.8

更改后index.php不会重新加载。 尽pipeindex.html确实如此。

这意味着,如果我通过我的浏览器请求网站,我得到旧的PHP文件,而不是在服务器上的新的。

如果我ssh进入服务器和sudo nano的PHP文件,它仍然不会更新。 这似乎是phpcaching在服务器上。

我试图从不同的机器访问该网站。 同样的问题。

我在网上search了很多。 大多数解决scheme围绕着将nginxconfiguration设置为sendfile off ,这是我做的,问题仍然存在。

如何让Nginx重新加载我更新的php文件?

最重要的文件:

nginx.conf

 user www-data; worker_processes auto; pid /run/nginx.pid; events { worker_connections 768; # multi_accept on; } http { ## # Basic Settings ## sendfile off; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; # server_tokens off; # server_names_hash_bucket_size 64; # server_name_in_redirect off; include /etc/nginx/mime.types; default_type application/octet-stream; ## # SSL Settings ## ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE ssl_prefer_server_ciphers on; ## # Logging Settings ## access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; ## # Gzip Settings ## gzip on; gzip_disable "msie6"; # gzip_vary on; # gzip_proxied any; # gzip_comp_level 6; # gzip_buffers 16 8k; # gzip_http_version 1.1; # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; ## # Virtual Host Configs ## include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; } #mail { # # See sample authentication script at: # # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript # # # auth_http localhost/auth.php; # # pop3_capabilities "TOP" "USER"; # # imap_capabilities "IMAP4rev1" "UIDPLUS"; # # server { # listen localhost:110; # protocol pop3; # proxy on; # } # # server { # listen localhost:143; # protocol imap; # proxy on; # } #} 

服务器块:test.mypersonalsite.com

 # Default server configuration # server { listen 80; listen [::]:80; root /var/www/html; index index.php index.html index.htm index.nginx-debian.html; server_name test.mypersonalwebsite.com; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { include snippets/fastcgi-php.conf; # With php7.0-cgi alone: # fastcgi_pass 127.0.0.1:9000; # # With php7.0-fpm: fastcgi_pass unix:/run/php/php7.0-fpm.sock; } } 

初始index.html v1.0.7

 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Nginx Test v1.0.7</title> </head> <body> <h1>Nginx Test v1.0.7</h1> <a href="/public" title="">Go to PHP file</a> </body> </html> 

初始index.php v1.0.7

 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>v1.0.7 - <?php echo "That's an nginx Test." ?></title> <link rel="stylesheet" href=""> </head> <body> <h1><?= "v1.0.7 - Just Testing PHP on Nginx." ?></h1> <a href="../" title="">Return to Index</a> <h4>Random PHP Generated Number: <?= rand(1, 100); ?> </h4> </body> </html> 

更新了index.html到v1.0.8(重新加载)

 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Nginx Test v1.0.8</title> </head> <body> <h1>Nginx Test v1.0.8</h1> <a href="/public" title="">Go to PHP file</a> </body> </html> 

更新index.php到v1.0.8(不重新加载)

 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>v1.0.8 - <?php echo "That's an nginx Test." ?></title> <link rel="stylesheet" href=""> </head> <body> <h1><?= "v1.0.8 - Just Testing PHP on Nginx." ?></h1> <a href="../" title="">Return to Index</a> <h4>Random PHP Generated Number: <?= rand(1, 100); ?> </h4> </body> </html> 

您正在重新启动错误的服务。 PHP 7现在cachingphp文件在fpm服务(nginx本身不处理PHP文件)。 根据您的操作系统和PHP的分布以下之一应该解决这个问题:

 service php-fpm restart # most centos service php7-php-fpm restart # centos and remi php7 service php7.0-fpm restart # ubuntu