通过Apache访问NextJS项目
通过Apache访问NextJS项目。
通过Apache将NextJS项目(next_app)公开为/next/路径。
説明パスNextJSのプロジェクトディレクトリ/www/js/next_app/URLhttp://xxx.local/next/
任务的目的
-
- 为了试验将与客户端通信的协议更改为HTTP/2(在NextJS中创建了HTTP/2自定义服务器的情况下,由于阅读了一篇文章,发现未执行处理的优化措施)。
- 为了在同一服务器上运行多个项目时,进行更改目录名称并进行发布的准备工作。
请重新阐述以下内容,只需一种选项:
任务的要求
在Apache中进行代理设置
如果要通过https进行公开,则需要将其添加到extra/httpd-ssl.conf文件中。
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
ProxyRequests Off
<Location /next_test/>
ProxyPass http://localhost:3000/
ProxyPassReverse http://localhost:3000/
</Location>
# systemctl restart httpd
建构Next的项目
$ cd /www/html/next_app
$ vi next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
assetPrefix: "/next",
basePath: "",
reactStrictMode: true,
images: {
unoptimized: true
},
}
module.exports = nextConfig
$ npm run build
$ npm start
备忘录
basePath是NextJS项目的目录,所以要设置为空白。
assetPrefix是生成的构建结果所引用的目录,所以要设置为/next。
这样,JS和图像文件的链接将以/next/开头,因此可以从Apache中引用。