node.js - I can't serve static by nginx -
i have following nodejs structure resides in /home/ubuntu/project directory:
sever site |-css | |-styles.css |-img | |-sprite.png |-js |-script.js
i'm trying serve static assets nginx, wrote following location:
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; } }
but when try open site in browser failed status on requested assets. whet's problem?
edit: route css example is:
http://www.myapp.com/css/styles.css
well,
add /
root path.
root /usr/share/nginx/www;
should
root /usr/share/nginx/www/;
use alias assets like:
alias /home/ubuntu/project/site/; (again, add last /)
these mess me:
location ~ ^/(images/|img/|javascript/|js/|css/|stylesheets/|flash/|media/|static/|robots.txt|humans.txt|favicon.ico|home/|html|xml)
you should check these http://wiki.nginx.org/nginxhttpcoremodule#location
i dont see these folders images/, javascript/, stylesheets/, flash/, media/, static/ , home/
in sitemap.
and these both |html|xml
looking route /html
or /xml
not .html
or .xml
files.
then try:
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 file extensions needed. alias /home/ubuntu/project/site/; access_log off; expires max; }
Comments
Post a Comment