繁体   English   中英

nginx和nodejs 404和403用于某些文件

[英]nginx and nodejs 404 & 403 for some of the files

我有安装了NGINX的NodeJS服务器,我建立了一个简单的页面,但是有些文件却显示404和403,我不知道为什么可能是愚蠢的://

非常感谢 : )

这是我的页面:

 <!DOCTYPE html> <html> <head> <title>Dummy Angular App</title> <link rel='stylesheet' href='/resources/stylesheets/style.css' /> <script src="/angular/angular.js"></script> <script src="/angular-route/angular-ui-router.js"></script> </head> <body> <h1>Dummy Angular App</h1> <p>No Angular Yet!</p> <script src="/resources/javascripts/app.js"></script> </body> </html> 

我有默认的NodeJS树:

 /myApp --------->/app --------->/node_modules -------------->/angular -------------->/angular-ui-router --------->/public -------------->/images -------------->/stylesheets -------------->/javascripts 

这是我的nginx配置:

 location /angular { root /srv/www/testapp/node_modules; try_files $uri $uri/ =404; } location /angular-route { root /srv/www/testapp/node_modules; rewrite /angular-route /angular-ui-router/release; try_files $uri $uri/ = 404; } location /resources/ { root /srv/www/testapp/public; rewrite_log on; error_log /var/log/nginx/localhost.error_log notice; rewrite ^/resources/(.*)$ /$1 last; try_files $uri $uri/ = 404; } location / { proxy_pass http://127.0.0.1:3000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; } 

  1. /resources/stylesheets/style.css-404
  2. /angular/angular.js- 工作
  3. /angular-route/angular-ui-router.js-禁止(与angular权限相同)
  4. /resources/javascripts/app.js-404

这是我的日志(似乎重写有效):

 2016/03/04 03:00:07 [notice] 9334#0: *14 "^/resources/(.*)$" matches "/resources/stylesheets/style.css", client: 10.0.0.3, server: webserver.com, request: "GET /resources/stylesheets/style.css HTTP/1.1", host: "www.webserver.com", referrer: "http://www.webserver.com/" 2016/03/04 03:00:07 [notice] 9334#0: *14 rewritten data: "/stylesheets/style.css", args: "", client: 10.0.0.3, server: webserver.com, request: "GET /resources/stylesheets/style.css HTTP/1.1", host: "www.webserver.com", referrer: "http://www.webserver.com/" 2016/03/04 03:00:07 [notice] 9334#0: *18 "^/resources/(.*)$" matches "/resources/javascripts/app.js", client: 10.0.0.3, server: webserver.com, request: "GET /resources/javascripts/app.js HTTP/1.1", host: "www.webserver.com", referrer: "http://www.webserver.com/" 2016/03/04 03:00:07 [notice] 9334#0: *18 rewritten data: "/javascripts/app.js", args: "", client: 10.0.0.3, server: webserver.com, request: "GET /resources/javascripts/app.js HTTP/1.1", host: "www.webserver.com", referrer: "http://www.webserver.com/" 2016/03/04 03:00:07 [notice] 9334#0: *16 "^/resources/(.*)$" matches "/resources/javascripts/app.js", client: 10.0.0.3, server: webserver.com, request: "GET /resources/javascripts/app.js HTTP/1.1", host: "www.webserver.com", referrer: "http://www.webserver.com/" 2016/03/04 03:00:07 [notice] 9334#0: *16 rewritten data: "/javascripts/app.js", args: "", client: 10.0.0.3, server: webserver.com, request: "GET /resources/javascripts/app.js HTTP/1.1", host: "www.webserver.com", referrer: "http://www.webserver.com/" 

尝试这个:

location /angular-route {
    root /srv/www/testapp/node_modules/angular-ui-router/release;
    rewrite ^/angular-route/(.*)$ /$1 break;
    try_files $uri $uri/ = 404;
}

location /resources/ {
    root /srv/www/testapp/public;
    rewrite ^/resources/(.*)$ /$1 break;
    try_files $uri $uri/ = 404;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM