Centos

NGINX 不提供 CSS 和 JS

  • December 1, 2013

NGINX 不會向瀏覽器提供 CSS 或 JS 文件

連結到頁面(magento)http://836237.vps-10.com/

訪問日誌顯示:

[01/Dec/2013:16:55:17 +0000] "GET /js/varien/form.js HTTP/1.1" 304 0 "http://836237.vps-10.com/" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36"

錯誤日誌顯示沒有錯誤。

以下是我的虛擬主機文件:

server {
listen       80 default_server;
server_name  836237.vps-10.com;
root   /data/www/public_html/hotnstylish/public/;

#charset koi8-r;
access_log  /data/www/public_html/hotnstylish/log/access.log;
error_log /data/www/public_html/hotnstylish/log/error.log;

location / {
include /etc/nginx/mime.types;
   root   /data/www/public_html/hotnstylish/public/;
   index  index.html index.htm index.php;
   try_files $uri $uri/ @handler; ## If missing pass the URI to Magento's front handler
   expires 30d; ## Assume all files are cachable

}

#error_page  404              /404.html;

# redirect server error pages to the static page /50x.html
#
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#    proxy_pass   http://127.0.0.1;
#}

## These locations would be hidden by .htaccess normally
location ^~ /app/                { deny all; }
location ^~ /includes/           { deny all; }
location ^~ /lib/                { deny all; }
location ^~ /media/downloadable/ { deny all; }
location ^~ /pkginfo/            { deny all; }
location ^~ /report/config.xml   { deny all; }
location ^~ /var/                { deny all; }


# media
location ~* \.(png|gif|jpg|jpeg|css|js|swf|ico)$ {
   root   /data/www/public_html/hotnstylish/public/;
   access_log off;
   expires 30d;
}



# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
 location ~ ^/(app|includes|lib|media/downloadable|pkginfo|report/config.xml|var)/ { internal; }
 location /var/export/ { internal; }
 location /. { return 404; }
 location @handler { rewrite / /index.php; }
 location ~* .php/ { rewrite ^(.*.php)/ $1 last; }
 location ~* .php$ {
if (!-e $request_filename) { rewrite / /index.php last; }
expires off;
root           /data/www/public_html/hotnstylish/public/;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE default;
fastcgi_param MAGE_RUN_TYPE store;
include fastcgi_params;

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

我的 Mime 在 /etc/nginx/ 中輸入:

types {
text/html                             html htm shtml;
text/css                              css;
text/xml                              xml;
image/gif                             gif;
image/jpeg                            jpeg jpg;
application/x-javascript              js;
application/atom+xml                  atom;
application/rss+xml                   rss;

請幫助解決這個問題的時間太長了!謝謝

清除瀏覽器記憶體。

304 表示“未修改”並指示瀏覽器提供其記憶體副本。

引用自:https://serverfault.com/questions/558511