项目使用node+express,express配置了路由如下: router.get('/’, function(req, res, next) { res.render(‘index’); }); router.get('/aaa’, function(req, res, next) { res.render(‘blog/aaa.html’); });
nginx配置: upstream nodeweb-server { server localhost:3000; } server { listen 80; server_name www.mywebsite.com mywebsite.com; location = / { root /; proxy_pass http://nodeweb-server; proxy_redirect off; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-NginX-Proxy true; } location ~ .*.(gif|jpg|jpeg|png|bmp|swf|js|css|woff|ttf|TTF|svg)$ { root /opt/NodeWeb/public/; if (-f $request_filename) { expires 100d; break; } }
这样,直接访问 mywebsite.com 是没问题的,但是访问mywebsite.com/aaa,就会出现“404 Not Found”的错误,nginx应该如何配置呢?