Nginx server (not showing changes) - Delete cache?

2019-09-14 22:22发布

问题:

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

回答1:

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