3

I have got a Symfony2.2.1 project which run with a nginx/1.2.6 (Ubuntu 13.04 VirtualBox). The render of assets are ok with hard link.

With symlink, it works only on the first initialisation. When I update a symlink source, the browser render transform my modifications with ����� characters. There is no errors from the browser and the part without modifications is not impacted.

Example of the end of my CSS file after modification:

[...]

div.form-actions {
    text-align: center;
}

�����

Currently, I use hard link. I had not this problem with Apache2... :/

Have you got an idea? Thanks

Nginx site conf:

server {
    listen 80;
    root /media/sf_NetBeansProjects/XXXX/web;
    index app.php;
    server_name XXXX.lo;

    location / {
        # try to serve file directly, fallback to rewrite
        try_files $uri @rewriteapp;
    }

    location @rewriteapp {
        # rewrite all to app.php
        rewrite ^(.*)$ /app.php/$1 last;
    }

    location ~ ^/(app|app_dev)\.php(/|$) {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param HTTPS off;
    }

    error_log /media/sf_NetBeansProjects/XXXX/app/logs/nginx_errors.log;
    access_log /media/sf_NetBeansProjects/XXXX/app/logs/nginx_access.log;
}

The subtlety is that the media/sf_NetBeansProjects is a VirtualBox share folder with my Windows8 but as I say previously, apache2 was always ok with that.

webda2l
  • 6,686
  • 2
  • 26
  • 28

5 Answers5

2

Try to restart php5-fpm, after create symlink.

sudo service php5-fpm reload

And check disable_symlinks option http://nginx.org/en/docs/http/ngx_http_core_module.html#disable_symlinks

d.garanzha
  • 813
  • 1
  • 9
  • 15
  • Restart fpm has no effect and about the option check, I had already check before posting on stackoverflow. The value is ok. – webda2l May 20 '13 at 21:03
1

Ok well there's one thing that comes up my mind, maybe you're viewing the binary data of the image file, so maybe the browser isn't identifying this as an image file, maybe cause nginx isn't sending the content-type, could be for another reason. but I have one suggestion, add this in your default location /

location / {
    try_files ..... ;
    types {
        image/jpeg   jpg jpeg;
    }
}

alternatively, you can include mime.types inside the server block

server {
    #bla bla bla
    include mime.types;
    location / {
        #bla bla
    }
}

I'm not sure if this will work or not, but it's worth a try.

Mohammad AbuShady
  • 40,884
  • 11
  • 78
  • 89
1

This article helped:

https://coderwall.com/p/ztskha

"Simply spoken, sendfile() uses kernel calls to copy files directly from disc to tcp. If you are using remote filesystems (like nfs or the VirtualBox Guest Additions stuff), this method isn't reliable."

Essentially, turn off sendfile for NGINX if you are trying to serve files on your guest VM that exist on your host.

"To turn off sendfile() in Apache, you can use the EnableSendfile off directive, for nginx use sendfile off."

  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Qantas 94 Heavy Nov 19 '13 at 01:53
0

Try clearing your browser cache sometimes nginx throw the the file as raw as in with no mime-type set. Also try changing the HttpHeaders set the expiration and cache-control of per file to minimum, it depends if your project is still in development. So that the file that is being push by the server is always updated and is not being cache by the browser.

Ed Abucay
  • 483
  • 7
  • 20
-1

I had the same problem, using the same setup.

You need to disable sendfile from Nginx in order to properly send this static files under symbolic links.

location / {
        sendfile off; # Do it before try files

        # try to serve file directly, fallback to rewrite
        try_files $uri @rewriteapp;
    }
Renato Mefi
  • 2,131
  • 1
  • 18
  • 27