0

/home/ubuntu/project ディレクトリにある次の nodejs 構造があります。

 sever
 site
   |-css
   |  |-styles.css
   |-img
   |  |-sprite.png
   |-js
     |-script.js

nginx で静的アセットを提供しようとしているので、次の場所を書きました。

upstream myapp_upstream {
    server 127.0.0.1:3000;
    keepalive 64;
}

server {
    listen 80;

    server_name www.myapp.com;

    error_page 400 404 500 502 503 504 /50x.html;
    location  /50x.html {
            internal;
            root /usr/share/nginx/www;
    }

    location ~ ^/(images/|img/|javascript/|js/|css/|stylesheets/|flash/|media/|static/|robots.txt|humans.txt|favicon.ico|home/|html|xml) {
        root /home/ubuntu/project/site;
        access_log off;
        expires max;
    }

    location / {
        proxy_redirect off;
        proxy_set_header   X-Real-IP            $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
        proxy_set_header   Host                   $http_host;
        proxy_set_header   X-NginX-Proxy    true;
        proxy_set_header   Connection "";
        proxy_http_version 1.1;
        proxy_pass         http://myapp_upstream;
        proxy_intercept_errors on;
    }
}

しかし、ブラウザで自分のサイトを開こうとすると、要求されたすべてのアセットで失敗ステータスが表示されます。問題は何ですか?

編集: たとえば、css への私のルートは次のとおりです。

http://www.myapp.com/css/styles.css
4

1 に答える 1

1

良い、

/ルート パスに a を追加します。

root /usr/share/nginx/www;

する必要があります

root /usr/share/nginx/www/;

次のようなアセットのエイリアスを使用します。

alias /home/ubuntu/project/site/; (again, add the last /)

これらは私にとって混乱です:

location ~ ^/(images/|img/|javascript/|js/|css/|stylesheets/|flash/|media/|static/|robots.txt|humans.txt|favicon.ico|home/|html|xml)

これらのhttp://wiki.nginx.org/NginxHttpCoreModule#locationを確認する必要があります

images/, javascript/, stylesheets/, flash/, media/, static/ and home/サイトマップにこれらのフォルダー が表示されません。

そして、これらはどちら|html|xml もルートを探している/html/xml.htmlまたは.xmlファイルを探していません。

次に試してください:

location ~ ^/(robots.txt|humans.txt) {
    alias /home/ubuntu/project/site/;
    access_log off;
    expires max;
}

location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {  //add here all the file extensions needed.
    alias /home/ubuntu/project/site/;
    access_log off;
    expires max;     
}
于 2013-05-19T19:39:59.663 に答える