我对当前的nginx配置有问题。我所试图做的是:nginx + nodejs配置
- 对于没有任何路径请求,得到的index.html(作品)
- 直接获取现有文件(作品)
- 如果请求的文件或路径不实际存在代理请求到nodejs(404)
我已经尝试了几种在stackoverflow上找到的配置,但没有一个符合我的需要。
这里是我当前的配置:
# IP which nodejs is running on
upstream app_x {
server 127.0.0.1:3000;
}
# nginx server instance
server {
listen 80;
server_name x.x.x.x;
#access_log /var/log/nginx/x.log;
root /var/www/x/public;
location/{
root /var/www/x/public;
index index.html index.htm index.php;
}
location ^/(.*)$ {
if (-f $request_filename) {
break;
}
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:3000;
}
}
只是删除'如果(-f $ REQUEST_FILENAME)'语句和突破?我真的不知道什么是工作,什么不工作,以及你的需求是什么。 – mekwall
你有没有为节点提供'index.html'的原因?这会让事情变得更容易。 – mekwall
我没有为nodejs提供index.html的原因是,它是静态html。该项目是一个Ajax驱动的应用程序,我试图用nodejs只提供json服务。 – Daniel