使用Caddy服务器在Docker内部部署动态Nextjs + Nodejs应用程序 [英] Deploying dynamic Nextjs + Nodejs application inside docker using caddy server

查看:163
本文介绍了使用Caddy服务器在Docker内部部署动态Nextjs + Nodejs应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个简单的投资组合应用程序,我的应用程序结构是这样的.Nextjs/客户端,Node.js/服务器Mongodb/db

I am currently developing a simple portfolio app and my app structure is like this. Nextjs/client, Nodejs/server, Mongodb/db

Nextjs在端口3001上本地托管,Nodejs应用程序在5000上本地托管.每当nextjs需要获取任何api时,它将调用nodejs应用程序.所有的东西都在docker内部配置.我对部署nextjs应用程序非常陌生,最近使用了带有自动https的caddy服务器.我能够使用命令静态部署nextjs应用程序

Nextjs is hosted locally on port 3001, Nodejs app on 5000. Whenever nextjs needs to fetch any api it calls nodejs application. All the things are configured inside docker. I am very new to deploying nextjs application and have recently used caddy server which has automatic https. I am able to deploy the nextjs application statically using commands

next build
next export

nextjs应用程序内部目录中名为index.html的静态导出文件指向端口80和443上的caddy服务器.静态导出的应用程序不支持我最近才知道的api路由.我尝试了 next build和next start 命令在.next目录中生成一个动态的生产版本.主要问题是如何将动态生成的nextjs应用程序指向docker容器内的caddy配置.我现在的球童配置看起来像

The statically exported file called index.html inside out directory of nextjs application is pointed to caddy server on port 80 and 443. Statically exported app doesn't support api routes which I recently came to know. I tried next build and next start command to generate a dynamic production build inside .next directory. The main problem is How do I point my dynamically generated nextjs application in caddy configuration inside docker container. My present caddy configuration looks like

www.example.com:443 {
 tls xyz@email.com
 root * /srv
 route {
   reverse_proxy /api* api-server:5000
   try_files {path} {path}/ /index.html
   file_server
   }
}

我正在寻找与代理服务器特别相关的提示.

I am looking for hints especially related to proxy server.

提前谢谢

推荐答案

我假设前端的 api网址看起来像这样 http://localhost:5000 (根据您的YouTube评论此处)无效如果您要从远程计算机(在这种情况下为您的计算机,因为我假设您的应用程序已托管)中访问dockerized应用程序.尝试将其更改为 https://www.example.com:5000 并重建图像.

I'm assuming the api url in your frontend looks like this http://localhost:5000 (based on your youtube comment here) which won't work if you're accessing your dockerized app from a remote computer (in this case your computer, since I'm assuming your app is hosted). Try changing it to https://www.example.com:5000 and rebuild your image.

这篇关于使用Caddy服务器在Docker内部部署动态Nextjs + Nodejs应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆