如何将 nuxt.js 应用程序部署到 Apache?

1 apache deployment nuxt.js

我用 nuxt.js 开始了自己的博客(静态内容)。但是当我将 nuxt.js 应用程序部署到 Apache 时遇到了一些问题。

我知道最好将 nuxt.js 部署到 Nginx,但除了 Apache 之外我别无选择。我为我的 nuxt.js 应用程序进行了代理设置以连接我的域。但只有主页有效,其他页面显示无效 DNS 错误消息。

我做了什么

  1. npm nuxt generate>npm nuxt start在我的 CLI 中
  2. httpd-vhost.conf 中的代理设置
<VirtualHost *:80>
    ServerName mydomain.com
    DocumentRoot "/Users/myname/projects"
    ProxyRequests OFF
    ProxyPreserveHost On
    ProxyPass / http://localhost:3000
    ProxyPassReverse / http://localhost:3000
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
  1. 当我浏览我的域时,会显示登录页面,但其他页面不会显示。
  • Clink 出版物页面 -> 显示“localhost:3000publications”的无效 DNS 错误
  • 图像(jpg、png)文件无法加载。

如何将 nuxt.js 部署到 Apache?

感谢您的帮助!

小智 6

  1. mod_proxy 配置的问题是您缺少代理 URL 的尾部斜杠,即两个指令必须是:

       ProxyPass / http://localhost:3000/
       ProxyPassReverse / http://localhost:3000/
    
    Run Code Online (Sandbox Code Playgroud)
  2. 但是,如果您使用 生成了静态 Nuxt 站点nuxt generate,并且需要使用 Apache 提供服务,则不需要使用 运行 Nuxt 应用程序nuxt start。相反,您可以直接使用 Apache 提供生成的静态文件。

    dist将 Nuxt 应用程序子目录的内容上传到 Apache DocumentRoot,删除代理配置指令,这应该就是所需的全部内容。