Nginx服务器(不显示更改) - 删除缓存? [英] Nginx server (not showing changes) - Delete cache?

查看:201
本文介绍了Nginx服务器(不显示更改) - 删除缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Nginx上运行了一个Laravel网站(Ubuntu)(不是一个虚拟框)。当我对css文件或任何文件的更改,我不能立即看到更改。我已尝试将sendfile从on更改为off,如此链接中所示:





我找不到一个Nginx缓存文件删除缓存。许多网站建议进入路径/到/缓存文件夹,但我找不到它:



https://www.nginx.com/blog/nginx-caching-guide/



反正我不相信我设置任何类型的代理缓存或任何东西。任何想法,我可以找到我的缓存,所以我可以删除它的人吗?为什么我想在这里做正确的事?感谢您提前回答。



这是我的测试服务器块看起来像:

  server {
#在htpasswd文件中使用用户名和密码的安全网站
auth_basicclosed website;
auth_basic_user_file /tmp/.htpasswd.txt;

listen(myip)default_server;
listen [::]:83 default_server ipv6only = on;


root / var / www / test /(sitefolder);
index index.php index.html index.htm;

#使站点可访问
server_name(myiphere);

location / {
#首先尝试以文件形式提供请求,然后以
#作为目录,然后返回显示一个404.
try_files $ uri $ uri / /index.php?$query_string;
#取消注释以在此位置启用naxsi
#include /etc/nginx/naxsi.rules
}
location〜\.php $ {
try_files $ uri /index.php = 404;
fastcgi_split_path_info ^(。+ \.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name
include fastcgi_params;
}

这是我真正的站点服务器块看起来像:

 服务器{
#在htpasswd文件中使用用户名和密码的安全网站
auth_basicclosed website;
auth_basic_user_file /tmp/.htpasswd.txt;

listen(myip)default_server;
listen [::]:81 default_server ipv6only = on;

root / var / www /(mysite)/ public;
index index.php index.html index.htm;

#从http:// localhost /
server_name(myip)访问网站;

location / {
#首先尝试以文件形式提供请求,然后以
#作为目录,然后返回显示一个404.
try_files $ uri $ uri / /index.php?$query_string;
#取消注释在此位置启用naxsi
#include /etc/nginx/naxsi.rules
}

位置〜\.php $ {
try_files $ uri /index.php = 404;
fastcgi_split_path_info ^(。+ \.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
include fastcgi_params;
}


解决方案

客户端缓存,而不是服务器。您应该清除浏览器的缓存以查看您的css更改。此外,浏览器缓存是css和javascript开发中的常见问题。幸运的是,你可以利用elixir,它与laravel 5.1一起提供,以防止浏览器缓存你的资产。



访问文档以获取更多关于laravel elixir的信息。 >

http:// laravel .com / docs / 5.1 / elixir#versioning-and-cache-busting



其次,laravel为我们提供了一个方便的命令来清除服务器的缓存: / p>

php artisan cache:clear



UPDATE: / p>

  server {
listen 80;
server_name example.com
root/ usr / share / nginx / app / public;

index index.html index.htm index.php;

charset utf-8;

location / {
try_files $ uri $ uri / /index.php?$query_string;
}

location = /favicon.ico {access_log off; log_not_found off; }
location = /robots.txt {access_log off; log_not_found off; }

access_log off;
error_log /var/log/nginx/app-error.log错误;

client_max_body_size 100m;

include hhvm.conf;

位置〜/\.ht {
拒绝所有;
}
}

服务器{
listen 80;
server_name beta.example.com;
root/ usr / share / nginx / beta / public;

index index.html index.htm index.php;

charset utf-8;

location / {
try_files $ uri $ uri / /index.php?$query_string;
}

location = /favicon.ico {access_log off; log_not_found off; }
location = /robots.txt {access_log off; log_not_found off; }

access_log off;
error_log /var/log/nginx/app-error.log错误;

client_max_body_size 100m;

include hhvm.conf;

位置〜/\.ht {
拒绝所有;
}
}


I'm running a Laravel Site (Ubuntu) on Nginx (Not a virtual box). When I make changes to a css file, or any file for that matter i'm unable to see the changes right away. I've tried changing sendfile from on to off as noted in this link:

How to clear the cache of nginx?

And I couldn't find a Nginx cache file to delete the cache. Many sites recommend going to the "path/to/cache" folder but I can't find it:

https://www.nginx.com/blog/nginx-caching-guide/

Anyway I don't believe I set up any kind of proxy caching or anything. Any ideas where I can find my cache so I can delete it folks? For that matter am I looking to do the correct thing here? Thanks for you answer in advance.

This is what my test server block looks like:

server { 
        # secure website with username and password in htpasswd file
       auth_basic "closed website";
       auth_basic_user_file /tmp/.htpasswd.txt;

        listen (myip) default_server;
        listen [::]:83 default_server ipv6only=on;


        root /var/www/test/(sitefolder);
        index index.php index.html index.htm;

        # Make site accessible
        server_name (myiphere);

location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ /index.php?$query_string;
            # Uncomment to enable naxsi on this location
            # include /etc/nginx/naxsi.rules
}
location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
}

This is what my real site server block looks like:

server {
        # secure website with username and password in htpasswd file
        auth_basic "closed website";
        auth_basic_user_file /tmp/.htpasswd.txt;

        listen (myip) default_server;
        listen [::]:81 default_server ipv6only=on;

        root /var/www/(mysite)/public;
        index index.php index.html index.htm;

        # Make site accessible from http://localhost/
        server_name (myip);

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ /index.php?$query_string;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }

 location ~ \.php$ {
                try_files $uri /index.php =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }

解决方案

First, css is something that the client caches, not the server. You should clear your browser's cache to see your css changes. Furthermore, browser caching is a common problem in css and javascript development. Luckily, you can take advantage of elixir, which ships with laravel 5.1, to prevent browsers caching your assets.

Visit the docs for more info on laravel elixir.

http://laravel.com/docs/5.1/elixir#versioning-and-cache-busting

Second, laravel gives us a convenient command to clear your server's cache:

php artisan cache:clear

UPDATE:

server {
    listen 80;
    server_name example.com;
    root "/usr/share/nginx/app/public";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/app-error.log error;

    client_max_body_size 100m;

    include hhvm.conf;

    location ~ /\.ht {
        deny all;
    }
}

server {
    listen 80;
    server_name beta.example.com;
    root "/usr/share/nginx/beta/public";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/app-error.log error;

    client_max_body_size 100m;

    include hhvm.conf;

    location ~ /\.ht {
        deny all;
    }
}

这篇关于Nginx服务器(不显示更改) - 删除缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆