Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

  • and << 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/;

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;
  access_log off;
  error_log on;

  location / {
    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

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

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

Your Answer


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.