简体   繁体   English

如何部署 Laravel + Nuxt 应用程序?

[英]How to deploy Laravel + Nuxt application?

I have built Web application using Laravel As API and Nuxt As Front and.我已经使用Laravel作为 API 和Nuxt作为 Front 构建了 Web 应用程序。 These 2 built desperately.这两个拼命建造。 When the development ongoing Its isn't an issue.当开发正在进行时,这不是问题。 Because i can run them using their own development servers.因为我可以使用他们自己的开发服务器运行它们。 Then i have bought a VPS server for host this.然后我买了一个VPS服务器来托管这个。 Now the question in how i deploy these two apps on my VPS .现在的问题是我如何在我的VPS上部署这两个应用程序。 Specially How i can deploy nuxt app correctly in vps .特别是我如何在vps中正确部署nuxt应用程序。 Its not static side.它不是 static 方面。 It is ssr app.它是ssr应用程序。

Essentially, you are going to need a few things:本质上,您将需要一些东西:

  • A server (which you already have)服务器(您已经拥有)
  • nginx nginx
  • PM2 PM2
  • Node/NPM installed已安装节点/NPM

The tricky part of this, is to make sure the server continues running and auto-restarts in case of a crash.棘手的部分是确保服务器继续运行并在发生崩溃时自动重启。 PM2 solves that issue, and you can read more information on how to use it here: https://nuxtjs.org/docs/2.x/deployment/deployment-pm2 PM2 解决了这个问题,您可以在此处阅读有关如何使用它的更多信息: https://nuxtjs.org/docs/2.x/deployment/deployment-pm2

You can install it by:您可以通过以下方式安装它:

npm install -g pm2

Which will install PM2 globally on your server and you'll have access to the pm2 command.这将在您的服务器上全局安装 PM2,您将可以访问 pm2 命令。

Follow the documentation above, and all you gotta do is run:按照上面的文档,你所要做的就是运行:

pm2 start all

This will start the Nuxt service and it will run on whichever port you've defined on your nuxt.config.js or package.json files.这将启动 Nuxt 服务,它将在您在nuxt.config.jspackage.json文件中定义的任何端口上运行。

Now that you've got your Nuxt instance running, you need to make sure that requests that come through the browser end up on the port that Nuxt is running on, that's achievable by using nginx's reverse proxy feature that you can read more about: https://nuxtjs.org/docs/2.x/deployment/nginx-proxy/现在您已经运行了 Nuxt 实例,您需要确保通过浏览器发出的请求最终到达 Nuxt 正在运行的端口,这可以通过使用 nginx 的反向代理功能来实现,您可以阅读更多信息: https ://nuxtjs.org/docs/2.x/deployment/nginx-proxy/

That documentation provides you with an example of an nginx config file, and you shouldn't really have to change anything other than the server_name, and the proxy_pass in case you've changed the default Nuxt port from 3000 to something else.该文档为您提供了 nginx 配置文件的示例,如果您已将默认 Nuxt 端口从 3000 更改为其他内容,则您无需更改 server_name 和 proxy_pass 以外的任何内容。

Additionally make sure that you have allowed port 80 to be listen on your server.此外,请确保您已允许端口 80 在您的服务器上进行侦听。

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

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