如何在phusion / passenger-nodejs docker容器中定义启动文件

问题描述 投票:0回答:1

我正在尝试让基于phusion / passenger-docker的docker容器中运行next.js应用程序。

我有一个基于乘客码头工人文档的完整设置,但是我从nginx看到404页面。

泊坞窗日志转储显示乘客或nginx正在寻找index.html

[error] 48#48: *1 "/home/app/nhe_app/index.html" is not found

我的启动文件是/home/app/nhe_app/server.js

Dockerfile最后阶段:

# Build production container from builder stage
FROM phusion/passenger-nodejs:1.0.8

# Set correct environment variables.
ENV HOME /root
ENV NODE_ENV=production

# Use baseimage-docker's init system.
CMD ["/sbin/my_init"]

# Enable Nginx and Passenger
RUN rm -f /etc/service/nginx/down

WORKDIR /home/app/nhe_app
RUN rm /etc/nginx/sites-enabled/default

COPY --chown=app:app ./nhe_app.conf /etc/nginx/sites-enabled/nhe_app.conf
COPY --chown=app:app ./secret_key.conf /etc/nginx/main.d/secret_key.conf
COPY --chown=app:app ./gzip_max.conf /etc/nginx/conf.d/gzip_max.conf

COPY --chown=app:app --from=builder /app/server.js /app/.env /home/app/nhe_app/
COPY --chown=app:app --from=builder app/src /home/app/nhe_app/src
COPY --chown=app:app --from=builder app/node_modules /home/app/nhe_app/node_modules

# Clean up APT when done.
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

nginx配置-nhe_app.conf:

server {
    listen 80;
    server_name glen-mac.local;
    root /home/app/nhe_app/server.js;

    passenger_enabled on;
    passenger_user app;
    passenger_startup_file server.js;
}

我希望乘客会启动nginx并运行我的应用。

[当我构建并启动docker容器时,似乎期望index.html

我正在使用docker image build -t nhe_app .

并与docker container run --name nhe_app -p 80:3000 nhe_app

浏览到http://glen-mac.local/显示了nginx的格式化404页面。

如何配置乘客码头工人寻找并执行我的server.js而不是index.html

docker passenger startup next.js phusion
1个回答
0
投票

OP问题中有几个细微的问题。

[最值得注意的是,Passenger似乎要求在上面的nginx配置中由root定义的应用程序根路径必须具有一个名为public的顶级文件夹。该文件夹不能包含index.html文件,并且可能应该为空。这在示例中显示,但并未在文档中明确说明是硬性要求。

第二个主要错误是,乘客绕过了应用程序server.js中指定的端口(在这种情况下为3000),并将其替换为nginx配置中指定的端口。因此,docker run命令从:

更改为

docker容器运行--name nhe_app -p 80:3000 nhe_app

to

docker容器运行--name nhe_app -p 80:80 nhe_app。

否则,我能提供的最佳建议是:

  1. 通过本地安装(无Docker)学习Passenger basics。使乘客演示应用程序正常工作。
  2. 让您的应用在该本地旅客安装中运行。
  3. 将您学到的知识应用于在docker-docker中实施您的应用程序。
© www.soinside.com 2019 - 2024. All rights reserved.