大佬教程收集整理的这篇文章主要介绍了node.js – 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; } }
try_files
与命名位置一起使用.
尝试使用以下配置:
# 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; LOCATIOn / { root /var/www/x/PUBLIC; index index.html index.htm index.PHP; try_files $uri $uri/ @node; } LOCATIOn @node { proxy_set_header Host $http_host; proxy_set_header X-ForWARDed-For $remote_addr; proxy_pass http://app_x; } }
注意:如果定义了上游,则应在proxy_ pass中使用该上游.此外,在代理时,始终添加X-Forwarded-For
标头.
以上是大佬教程为你收集整理的node.js – nginx nodejs配置全部内容,希望文章能够帮你解决node.js – nginx nodejs配置所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。