Intermittent 404s when requesting a CSS file
Gustavo Tenrreiro
gustavo at tenrreiro.com
Thu Jan 17 17:09:19 UTC 2013
Hi,
Just installed nginx and I am also using php5-fpm on Ubuntu.
I created a very simple php page that has a css stylesheet reference at the
top the of the generated HTML.
Every 2 or 3 requests however the browser request for the css file returns a
404 (nginx 404). When that happens in the response headers I see:
X-Powered-By PHP/5.3.10-1ubuntu3.4
Which I think means that nginx sent the request to the php service instead
of serving the css file itself.
Can someone help me figure out why this is happening? ( see below for my
nginx default.conf )
server {
listen 80;
server_name localhost;
expires off;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
root /home/gustavo/nginx/html;
location ~* /css/.*\.css$ {
add_header Content-Type text/css;
}
location ~ \.js {
add_header Content-Type
application/x-javascript;
}
location / {
#root /usr/share/nginx/html;
index index.html index.htm;
}
#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 /usr/share/nginx/html;
#root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# enforce NO www
if ($host ~* ^www\.(.*))
{
set $host_without_www $1;
rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
}
# canonicalize codeigniter url end points
# if your default controller is something other than "welcome" you
should change the following
if ($request_uri ~* ^(/welcome(/index)?|/index(.php)?)/?$)
{
rewrite ^(.*)$ / permanent;
}
# removes trailing "index" from all controllers
if ($request_uri ~* index/?$)
{
rewrite ^/(.*)/index/?$ /$1 permanent;
}
# removes trailing slashes (prevents SEO duplicate content issues)
if (!-d $request_filename)
{
rewrite ^/(.+)/$ /$1 permanent;
}
# removes access to "system" folder, also allows a "System.php"
controller
if ($request_uri ~* ^/system)
{
rewrite ^/(.*)$ /index.php?/$1 last;
break;
}
# unless the request is for a valid file (image, js, css, etc.), send to
bootstrap
if (!-e $request_filename)
{
rewrite ^/(.*)$ /index.php?/$1 last;
break;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
#root /home/gustavo/nginx/html;
try_files $uri = 404;
#fastcgi_split_path_info ^(.+\.php)(/.+)$;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20130117/7a26fa90/attachment.html>
More information about the nginx
mailing list