2016-08-24 21 views
0

私はノードアプリケーションを持っています。スタイルシート、javascript、imagesディレクトリは、メインノードのappディレクトリのパブリックディレクトリにあります。NGINXプロキシとNodeJSアプリケーション:hrefとsytylesheetsとjavascripts

index.htmlがレンダリングされると、これらのディレクトリへのHTML href呼び出しが失敗します。プロキシは、hrefに場所が指定されていないため、プロキシはルーティング方法を認識しません。

これは、NginxかNodeのどちらの問題であるかに悩まされています。私はこの問題がないTomcatのような他のWebサーバーに代理することができます。

レンダリングされたHTML:

<link rel='stylesheet' href='/stylesheets/foundation.min.css' /> 
<link rel='stylesheet' href='/stylesheets/motion-ui.css' /> 
<link rel='stylesheet' href='/stylesheets/foundation-icons/foundation-icons.css' /> 
<link rel='stylesheet' href='/stylesheets/js-image-slider.css' /> 
<link rel='stylesheet' href='/stylesheets/generic.css' /> 
<link rel='stylesheet' href='/stylesheets/style.css' /> 
<script src="/javascripts/js-image-slider.js"></script> 
<script src="/javascripts/vendor/modernizr.js"></script> 

nginxの:場所は

私はブログに基づいて、この上の多くのバリエーションを試してみましたが、仕事どれを見つけていません。

location/{ 
     root html; 
     index index.html index.htm; 
    } 
    error_page 500 502 503 504 /50x.html; 
    location = /50x.html { 
     root html; 
    } 

    #Node App Server : latest try 
    location ~ /internship { 
     proxy_set_header X-Real-IP $remote_addr; 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     proxy_set_header Host $http_host; 
     proxy_set_header X-NginX-Proxy true; 
     proxy_pass http://127.0.0.1:3000; 
    } 

    #Tomcat server 
    location /bi { 
      rewrite ^/bi(.*) /$1 break; 
      proxy_pass http://127.0.0.1:5566; 
      proxy_set_header Host $host; 
    } 
+0

hrefのパスから先頭の '/'を削除する必要があることがわかりました。 – James

答えて

0

Nginxにもう少し詳しくお読みください。 あなたの問題については、応答としてファイルを返送するものは何も持っていないようです。 nginxのドキュメントを見て は、画像を返すために、次の例を示します。

location /images/ { 
    try_files $uri /images/default.gif; 
} 

この例は、の/画像位置の接頭辞を探し/し、それは他の要求された場所は、デフォルトの画像を返す見つけるしようとするでしょう。 スタイルシートとjsで同様のリクエストを行うことができます。

は、あなたが簡単にあなたのウェブサイトの他の部分へのアクセスを拒否しないことにより、セキュリティホールを開くことができますので、しかし、私はこれらのディレクティブが何を意味するか模索し、もう少し時間を費やすだろうtry_files documentation here.

を見てみましょう。

関連する問題