【问题标题】:Nginx server (not showing changes) - Delete cache?Nginx 服务器(未显示更改) - 删除缓存?
【发布时间】:2015-10-15 19:17:34
【问题描述】:

我在 Nginx(不是虚拟机)上运行 Laravel 站点(Ubuntu)。当我对 css 文件或与此相关的任何文件进行更改时,我无法立即看到更改。我已尝试将 sendfile 从打开更改为关闭,如此链接中所述:

How to clear the cache of nginx?

而且我找不到 Nginx 缓存文件来删除缓存。许多网站建议转到“path/to/cache”文件夹,但我找不到:

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

无论如何,我不相信我设置了任何类型的代理缓存或任何东西。有什么想法可以找到我的缓存以便我可以删除它吗?就此而言,我是否希望在这里做正确的事情?感谢您提前回答。

这是我的测试服务器块的样子:

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;
}

这是我的真实站点服务器块的样子:

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;
        }

【问题讨论】:

  • 您是否尝试过清除浏览器的缓存? Css 通常由客户端缓存,而不是服务器。

标签: php css nginx server digital-ocean


【解决方案1】:

首先,css 是客户端缓存的东西,而不是服务器。您应该清除浏览器的缓存以查看您的 css 更改。此外,浏览器缓存是 css 和 javascript 开发中的常见问题。幸运的是,您可以利用 laravel 5.1 附带的 elixir 来防止浏览器缓存您的资源。

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

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

其次,laravel 给了我们一个方便的命令来清除你的服务器缓存:

php artisan cache:clear

更新:

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;
    }
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-28
  • 1970-01-01
  • 2021-07-14
  • 1970-01-01
  • 1970-01-01
  • 2018-03-29
相关资源
最近更新 更多