Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Whats strange is that this exact configuration used to work fine, but now all static files will 404 on direct link i.e

  • domain.com/test.html
  • domain.com/test/test.html
  • domain.com/ and domain.com/test/ << does work if index.html is present

this is the same for all static filetypes.

Nginx.conf :

user www;
worker_processes 8;
worker_rlimit_nofile 65536;

error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

events {
  worker_connections 1024;
  use epoll;
}

http {
  server_names_hash_bucket_size 64;
  include /etc/nginx/mime.types;
  default_type application/octet-stream;
  access_log /var/log/nginx/access.log;
  sendfile off;
  tcp_nopush on;
  tcp_nodelay on;

  proxy_cache_path                /web-cache/cache levels=2:2 keys_zone=basic:8m max_size=512m inactive=60m;
  proxy_temp_path                 /web-cache/cache_temp;

  proxy_redirect     off;

  proxy_set_header        Host            $host;
  proxy_set_header        X-Real-IP       $remote_addr;
  proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;

  ssl_session_cache    shared:SSL:10m;
  ssl_session_timeout  10m;

  #gzip compression options
  gzip on;
  gzip_static off;
  gzip_http_version 1.0;
  gzip_comp_level 9;
  gzip_min_length 128;
  gzip_buffers 16 8k;
  gzip_proxied any;
  gzip_types text/plain text/css text/xml text/javascript application/xml         application/xml+rss application/javascript application/json;
  gzip_disable "MSIE [1-6]\.";
  gzip_vary on;

  # include virtual hosts configuration
  include /etc/nginx/virtual.d/*.conf;
}

Virtualhost example :

server {
  listen 80;
  server_name domain.com www.domain.com;
  access_log off;
  error_log on;

  location / {
    proxy_pass http://127.0.0.1:6666;
    include /etc/nginx/nocache.conf;
  }
  location ~* ^.+\.(htm|html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|bz2|pdf|odt|txt|tar|bmp|rtf|js|swf|avi|mp4|mp3|ogg|flv)$ {
    expires 30d;
    root /home/test/public_html;
  }
}
share|improve this question
    
what's in your logs? did anything change since it was last working? –  Drew Khoury Sep 14 '13 at 3:32
add comment

2 Answers

The obvious problem is that you have placed root inside a location block. Best practice is to place it in the server block. This is one of the most common nginx misconfigurations.

share|improve this answer
    
Thanks for the reply, but even after editing the vhost and adding root to the server block and removing the one in location block it is still occurring, any ideas ?. –  user2778232 Sep 14 '13 at 1:41
add comment

I believe logs will show what files exactly nginx tries to pick up.

Possible investigation results are:

  1. File exists, but www user doesn't have enough permissions to access it.
  2. Nginx uses location /
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.