Images are missing in drupal 7 working on nginx

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
Dew's picture

I welcome,

I am here new and if I am writing in the bad department I apologise. Around drupalem earlier I already had the contact but now already on seriously and wants on the base drupal 7 to build the web page. My server is VPS with the system ubuntu, I installed server www nginx(NGINX + PHP-FPM), because he is being efficienting very much and here my problem appeared. Because images which he is adding aren't reading carefully to articles. After using automatic sending the picture to the server the link to him is following:

http://site.com/sites/default/files/field/image/my_image_fakt02022011_47...

But already after writing articles the link is following:

http://site.com/sites/default/files/styles/large/public/field/image/my_i...

And he isn't being shown, and if I write the link of the picture down in the browser:

http://site.com/sites/default/files/styles/large/public/field/image/my_i...

Server nginx is giving mistake 404: 404 Not Found nginx/0.8.54. I configured nginx according to it: http://wiki.nginx.org/Drupal Perhaps somebody had similar probilem and does know how to fix it? I will still add that for the keying become integrated of editor wyswig tinymce. On lighttpd everything acted well but how I changed the www server on nginx then images don't just work

my real address is replacing sites with site.com, clean URL work, only images work not (NGINX + PHP-FPM)

I apologise for my weak English very thanks

Comments

If you're using Drupal 7 and

brianmercer's picture

If you're using Drupal 7 and the config from http://wiki.nginx.org/Drupal then change:

        # Fighting with ImageCache? This little gem is amazing.
        location ~ ^/sites/.*/files/imagecache/ {
                try_files $uri @rewrite;
        }

to
        # For Drupal7 use /styles instead of /imagecache
        location ~ ^/sites/.*/files/styles/ {
                try_files $uri @rewrite;
        }
Dew's picture

I thank for a prompt reply but I don't know why but is out of order. At me in the catalogue files none is other. and should be this way styles/large/public/field/image/

/etc/nginx/sites-available
default

# You may add here your
# server {
#  ...
# }
# statements for each of your virtual hosts to this file

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/Quickstart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx/examples/ for more detailed examples.
##

server {
listen   80; ## listen for ipv4; this line is default and implied
  #listen   [::]:80 default ipv6only=on; ## listen for ipv6

root /var/www;
index index.php index.html index.htm;

# Make site accessible from http://site.com
    server_name site.com ;

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

        location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
        }

        # This matters if you use drush
        location = /backup {
                deny all;
        }

        # Very rarely should these ever be accessed outside of your lan
        location ~* .(txt|log)$ {
                allow 192.168.0.0/16;
                deny all;
        }

        location ~ ../..php$ {
                return 403;
        }



location / {
                # This is cool because no php is touched for static content
                try_files $uri @rewrite;
  }

location @rewrite {
                # Some modules enforce no slash (/) at the end of the URL
                # Else this rewrite block wouldn't be needed (GlobalRedirect)
                rewrite ^/(.)$ /index.php?q=$1;
        }


  location /doc {
        root /usr/share;
       autoindex on;
      allow 127.0.0.1;
       deny all;
  }



  #error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html
#
  #error_page 500 502 503 504 /50x.html;
#location = /50x.html {
    #   root /var/www;
#}

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
  #location ~ .php$ {
   #   proxy_pass http://127.0.0.1;
   #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  
  



    location ~ .php$ {
        fastcgi_pass 127.0.0.1:9000;
       fastcgi_index index.php;
       include fastcgi_params;
    }

location ~ ^/sites/./files/styles/ {
                try_files $uri @rewrite;
        }
       

location ~
.(js|css|png|jpg|jpeg|gif|ico)$ {
                expires max;
                log_not_found off;
        }
}

    # deny access to .htaccess files, if Apache's document root
   # concurs with nginx's one
    #
  #location ~ /.ht {
    #   deny all;
  #}



# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
#    listen 8000;
#  listen somename:8080;
# server_name somename alias another.alias;
# root html;
#    index index.html index.htm;
#
# location / {
#      try_files $uri $uri/ /index.html;
# }
#}


# HTTPS server
#
#server {
# listen 443;
#   server_name localhost;
#
#  root html;
#    index index.html index.htm;
#
# ssl on;
#   ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
#
#   ssl_session_timeout 5m;
#
# ssl_protocols SSLv3 TLSv1;
#    ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;
#    ssl_prefer_server_ciphers on;
#
#   location / {
#      try_files $uri $uri/ /index.html;
# }
#}

nginx.conf
user www-data;
worker_processes 2;
pid /var/run/nginx.pid;

events {
worker_connections 768;
    # multi_accept on;
}

http {

  ##
# Basic Settings
   ##

    sendfile on;
   tcp_nopush on;
tcp_nodelay on;
    keepalive_timeout 652;
types_hash_max_size 2048;
  # server_tokens off;

  # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
default_type application/octet-stream;

    ##
# Logging Settings
##

    access_log /var/log/nginx/access.log;
  error_log /var/log/nginx/error.log;

   ##
# Gzip Settings
    ##

    gzip on;
   gzip_disable "msie6";

   # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
   # gzip_buffers 16 8k;
  # gzip_http_version 1.1;
   # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

 
   ##
# Virtual Host Configs
##

    include /etc/nginx/conf.d/.conf;
 
   include /etc/nginx/sites-enabled/
;
}



#mail {
# # See sample authentication script at:
#    # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
#    # auth_http localhost/auth.php;
#   # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
#      listen     localhost:110;
#     protocol   pop3;
#      proxy      on;
#    }
#
#  server {
#      listen     localhost:143;
#     protocol   imap;
#      proxy      on;
#    }
#}

Sorry, the default markdown

brianmercer's picture

Sorry, the default markdown filter on this site mangles code. Change:

        # Fighting with ImageCache? This little gem is amazing.
        location ~ ^/sites/.*/files/imagecache/ {
                try_files $uri @rewrite;
        }

to
        # For Drupal7 use /styles instead of /imagecache
        location ~ ^/sites/.*/files/styles/ {
                try_files $uri @rewrite;
        }

and include the asterisks (*).

I thank! is acting!

Dew's picture

I thank! is acting!

This will also do

perusio's picture

A simpler regex.

No need to mix in the sites directory.

location ~* files/styles {
    access_log off;
    expires 30d;
    try_files $uri @rewrite;
}

Also, like I told you on the Nginx ML, your rewrite can be made simpler:

location @rewrite {
    rewrite ^ /index.php last;            
}

Perfect!

rterrero's picture

It works for me.
THANKS!!!!!

Worked for me

praideal's picture

Worked like a charm,

I added these lines into my /etc/nginx/sites-available/default file and everything is working fine now.

Thank you Perusio

Thank you both!

esod's picture

Both solutions solved the issue. Not mixing in the sites directory makes for a briefer directive, which I assume is always a good thing. Will you direct me to your reference to "Nginx ML"? That one didn't work for a reason unknown to me.

Finaly ! You realy saved my

RedJane's picture

Finaly ! You realy saved my day... this was getting me crazy :-)
Everytime I overlooked the ".../files/imagecache/..." in my conf file, grrr.
I didnt know where to look anymore cause I never received an error messages in my log files.
Thank you very much !

Thanks its also work for me

nehapandya55's picture

But Sequence also matters when i write

location ~* files/styles {
access_log off;
expires 30d;
try_files $uri @rewrite;
}
location @rewrite {
rewrite ^ /index.php last;
}

in nginx default file it didn't work but when i changed the sequence and write like:

location @rewrite {
rewrite ^ /index.php last;
}
location ~* files/styles {
access_log off;
expires 30d;
try_files $uri @rewrite;
}

it worked for me.

Nginx

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week