我正在尝试使用在docker中运行的nginx创建一个反向代理。我已经设置了nginx.conf文件,它在本地运行良好。但是,我不知道如何用这个更改的nginx.conf文件来设置nginx对接程序。有办法这样做吗?
更新:我已经能够在Docker中更改nginx.conf文件。然而,到localhost:80/go返回一个502坏网关。我有一个go应用程序运行在端口8081使用go运行main.go和一个python应用程序运行在端口8080使用烧瓶运行。我在一辆曼吉罗机器上。这是nginx.conf文件的服务器部分。
server {
listen 80;
location / {
return 200 'hey there, welcome to our amazing app :)';
}
location /cbl {
proxy_pass http://127.0.0.1:8080;
}
location /go {
proxy_pass http://127.0.0.1:8081;
}
}这是Dockerfile
FROM nginx
RUN mv /etc/nginx/nginx.conf /etc/nginx/nginxorig.conf
#RUN pwd
#RUN cp /home/shark/hwr-nginx/nginx.conf /etc/nginx/conf.d/default.conf
VOLUME /usr/share/nginx/html
VOLUME /etc/nginx我该怎么解决这个问题?
[shark@shark-virtualbox hwr-nginx]$ sudo docker build . -t nginx
Sending build context to Docker daemon 7.168kB
Step 1/3 : FROM nginx
---> 7084cd82dcbb
Step 2/3 : RUN mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf_orig
---> Running in 80e011c5b125
mv: cannot stat '/etc/nginx/nginx.conf': No such file or directory
The command '/bin/sh -c mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf_orig' returned a non-zero code: 1
[shark@shark-virtualbox hwr-nginx]$ cat Dockerfile
FROM nginx
RUN mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf_orig
RUN cp hwr-nginx/nginx.conf /etc/nginx/nginx.conf
```` RUN mv and RUN cp are also not working for me :(.发布于 2022-01-16 23:36:54
您需要将nginx.conf复制到容器中:
例如:COPY conf /etc/nginx
发布于 2022-01-16 23:39:43
在Dockerfile中,添加一条指令,将项目的反向代理配置的ngxin.conf复制到您要构建的对接映像中,位置是nginx将查找其配置的位置。例如,假设您的基本映像是Debian,您可以在Dockerfile中执行以下操作
# Move the default conf out of the way
RUN mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf_orig
# Copy in your project's new nginx conf
RUN cp my_project/nginx.conf /etc/nginx/nginx.confhttps://stackoverflow.com/questions/70735058
复制相似问题