tags:

views:

22

answers:

2

Hi, we have a FreeBSD OS system, an nginx webserver and php-fpm as PHP CGI. Sometimes .js and .css files are loaded only partly, about 5-7 words in the end of the file are missing, so we have a problem with visual part of our site as it becomes ugly cause of partly loaded javascript or css file. We tried to disable gzip, but it did not help us. Usually this happens after we upload modified css or javascript file.

Nginx version: 0.7.65

Nginx configuration:

worker_processes  100;
worker_priority -5;
worker_rlimit_nofile 51200;

events {
    worker_connections  51200;
    use kqueue;
}

http {
    include mime.types;
    default_type  application/octet-stream;
    log_format main '$remote_addr - $remote_user [$time_local] ' '"$request_filename" $status $body_bytes_sent ' '"$http_referer" "$http_user_agent" "$http_x_forwarded_for"';
    server_names_hash_bucket_size 512;
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 70 30;
    send_timeout 30s;
    reset_timedout_connection on;
    resolver 127.0.0.1;
    resolver_timeout 10s;

    server_tokens off;
    client_max_body_size 5m;

    open_file_cache max=100000 inactive=40s;
    open_file_cache_valid 60s;
    open_file_cache_min_uses 2;
    open_file_cache_errors on;

#gzip on;

.................. ..................

I hope this part of configuration will be enough to help us.

A: 

Usually this happens after we upload modified css or javascript file.

is your nginx trying to deliver content that is not uploaded fully yet?

if so, try to upload the files to another part of the system first and the move / copy the content atomic.

akira
A: 

This problem is the result of open_file_cache.

Reason

open_file_cache tests if the file was changed by comparing the file's inode. When you change your file in place, Nginx does not notice the change and returns old content. And since open_file_cache is local to every Nginx's worker, it may return the correct new contect or the old content depending on which worker is processing the request.

Workaround

Either you should not use it for files with changing content (turn it off for specific locations: open_file_cache off) or do atomic file updates as akira suggested (using mv or rename).

Alexander Azarov