简体   繁体   English

是否像php一样从nginx服务nodejs应用程序?

[英]Serve nodejs app from nginx like with php?

I use Nginx to serve my php applications for dev purposes. 我使用Nginx为开发目的提供服务。

On Ubuntu it works out of the box. 在Ubuntu上,它可以直接使用。

I want to do the same for Node.js apps. 我想对Node.js应用程序执行相同的操作。

  • Is this possible without doing nodejs app.js before? 如果不nodejs app.js ,这可能吗?
  • How to achieve this in a single Nginx conf file? 如何在单个Nginx conf文件中实现此目标?

PHP and node.js are oil and water. PHP和node.js是石油和水。 PHP requires a web server to run the .php files, however node.js typically creates its own web server. PHP需要Web服务器来运行.php文件,但是node.js通常会创建自己的Web服务器。 Since you are creating your own web server, in many cases you wouldn't find it necessary to serve your application from Nginx, however, if you truly insisted on "serving" it from Nginx, you would need to proxy it. 由于您正在创建自己的Web服务器,因此在很多情况下,您并不需要从Nginx提供服务,但是,如果您真正坚持要从Nginx“提供”服务,则需要代理它。

  • This is not possible without doing nodejs app.js before, due to the way node.js works. 由于node.js的工作方式,因此如果不先执行nodejs app.js ,这是不可能的。
  • This question best answers your question regarding proxy'ing via Nginx. 这个问题最好地回答了您关于通过Nginx进行代理的问题。

As a closing remark, its good to remember that node.js does in fact (in most cases) implement its own web server, and PHP does not. 最后,请记住,node.js实际上(在大多数情况下)确实实现了自己的Web服务器,而PHP没有实现。

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

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