小编Dan*_*iel的帖子

nginx + nodejs配置

我的当前nginx配置有问题.我想要做的是:

  • 对于没有任何路径的请求,获取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;
}
}
Run Code Online (Sandbox Code Playgroud)

nginx node.js

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

nginx ×1

node.js ×1