我们在使用Nginx + MySQL + PHP-FPM(以及WordPress作为CMS)的大多数服务器上遇到问题:浏览器不显示我们网页的最新版本。
我会这样解释:
但是在我们的一台服务器中,更糟糕的是,有些用户必须在浏览器上清理caching(例如Internet Explorer,显示出严重的问题),然后他们才能看到新的文章最终发布。
当用户在post上添加新评论时也会发生同样的情况:除非他刷新网页,否则不会显示该评论。 一切似乎caching,但我不知道为什么。
我在这些博客上没有在wordpress中使用任何caching插件,所以这可能发生的唯一原因是在Nginx中configuration不当。
根据要求,这里有两个“重要”文件:
/etc/nginx/nginx.conf user www-data; worker_processes 4; error_log /var/log/nginx/error.log; pid /var/run/nginx.pid; events { worker_connections 4096; use epoll; multi_accept on; accept_mutex_delay 50ms; } http { include /etc/nginx/mime.types; access_log /var/log/nginx/access.log; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; tcp_nodelay on; expires max; server_tokens off; gzip on; gzip_static on; gzip_proxied any; gzip_types text/plain text/css application/x-javascript text/xml text/javascript application/xml; gzip_vary on; gzip_disable "MSIE [1-6]\.(?!.*SV1)"; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; }
和/etc/nginx/sites-enabled/mysite.com
server { listen 80; server_name mysite.com *.mysite.com; rewrite ^/(.*) http://www.mysite.com/$1 permanent; } server { listen 80; # access_log /var/www/mysite/log/access.log; # error_log /var/www/mysite/log/error.log info; server_name www.mysite.com; root /var/www/mysite/; location / { index index.php; try_files $uri $uri/ /index.php?q=$uri&$args; # if the requested file exists, return it immediately if (-f $request_filename) { break; } # all other requests go to WordPress if (!-e $request_filename) { rewrite . /index.php last; } } ## Images and static content is treated different location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ { access_log off; expires 30d; root /var/www/mysite/; } ## Parse all .php file in the /var/www directory location ~ .php$ { fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_pass backend; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/mysite/$fastcgi_script_name; include fastcgi_params; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_intercept_errors on; fastcgi_ignore_client_abort on; fastcgi_read_timeout 180; } ## Disable viewing .htaccess & .htpassword location ~ /\.ht { deny all; } } upstream backend { server 127.0.0.1:9000; } }
希望有帮助…
您已经expires max;
在你的http
部分中,这将Expires
头设置为2037年12月31日23:59:59 GMT,并将Cache-Control max-age
为10年。