简体   繁体   English

使用 Docker 时如何修改 nginx.conf?

[英]How do I modify nginx.conf when utilizing Docker?

I have inherited a Microsoft Visual Studio MVC project for modification and I now need to allow users to upload files to the web server.我继承了一个Microsoft Visual Studio MVC 项目进行修改,我现在需要允许用户将文件上传到 web 服务器。 I utilize Windows 11 and IIS Express from within MS Visual Studio for development purposes and there is no issue with IIS.我在MS Visual Studio中使用Windows 11IIS Express用于开发目的, IIS. However, the app runs in production on a Ubuntu-based server running NGINX as a web server.但是,该应用程序在Ubuntu-based服务器上运行,该服务器运行NGINX作为 web 服务器。

PROBLEM: When I attempt to upload a file larger than 1MB from my browser to the production server I receive the error message "413 Request Entity Too Large."问题:当我尝试将大于 1MB 的文件从浏览器上传到生产服务器时,我收到错误消息“413 Request Entity Too Large”。 After scouring the web I have discovered: (a) NGINX invokes the 1MB limit by default;在搜索了 web 之后,我发现:(a) NGINX默认调用 1MB 限制; and (b) it is necessary to modify the nginx.conf file by adding the NGINX "client-max-body-size" directive. (b) 有必要通过添加NGINX “client-max-body-size”指令来修改nginx.conf文件。

I have located the nginx.conf file on the production server and have browsed it with Nano.我在生产服务器上找到了nginx.conf文件,并用Nano. However, I have stopped short of attempting to modify and save the file due to the presence of Docker.但是,由于Docker. Admittedly, I know virtually nothing of Docker and, unfortunately, the principals who set up this server have long since departed the Company.诚然,我对Docker几乎一无所知,不幸的是,设置此服务器的负责人早已离开公司。 Furthermore, it is unclear to me whether simply modifying the nginx.conf file and restarting NGINX on the production server will do the trick given what I presume to be the necessity to involve Docker.此外,鉴于我认为有必要涉及 ZC5FD214CDD0D2B3B4272E73B202,我还不清楚是否简单地修改nginx.conf文件并在生产服务器上重新启动NGINX是否可以Docker.

As an aside, my customer utilizes Azure DevOps to facilitate collaboration.顺便说一句,我的客户利用Azure DevOps来促进协作。 I regularly stage changes to my project using Git from within MS Visual Studio and subsequently use a Ubuntu update_app.sh script to push the changes into production.我定期使用MS Visual Studio中的Git对我的项目进行更改,随后使用Ubuntu update_app.sh脚本将更改推送到生产中。 I had previously attempted to modify the nginx.conf file included with the local copy of my MVC project.我之前曾尝试修改我的 MVC 项目的本地副本中包含的nginx.conf文件。 The file was pushed via Azure DevOps to the production server but the modified nginx.conf file would not push to production, presumably due to the presence of Docker.该文件通过Azure DevOps推送到生产服务器,但修改后的nginx.conf文件不会推送到生产,可能是由于存在Docker.

I would appreciate someone providing me with an explanation of the interaction between Docker and NGINX.我很感激有人向我解释DockerNGINX. I would further appreciate any tip on how to get the modified nginx.conf file pushed into production.我将进一步感谢有关如何将修改后的nginx.conf文件推入生产的任何提示。

Thanks in advance for your assistance.提前感谢你的帮助。

Thankfully this is pretty straightforward and NGIX has good documentation on this topic (see Copying Content and Configuration Files from the Docker Host section of Deploying NGINX and NGINX Plus on Docker ). Thankfully this is pretty straightforward and NGIX has good documentation on this topic (see Copying Content and Configuration Files from the Docker Host section of Deploying NGINX and NGINX Plus on Docker ).

  1. Find the Dockerfile for the deployed solution (typically in project or solution root directory)查找已部署解决方案的Dockerfile (通常在项目或解决方案根目录中)
  2. Copy the contents of the current NGIX configuration file (either from browsing the container image or finding configuration files within source)复制当前 NGIX 配置文件的内容(通过浏览容器镜像或在源代码中查找配置文件)
  3. Create a directory named conf within your source.在您的源代码中创建一个名为conf的目录。
  4. Copy the current configuration into the a file within conf and apply any changes to the configuration file.将当前配置复制到conf中的 a 文件中,并对配置文件应用任何更改。
  5. Update Dockerfile to copy files within conf into the container where NGIX loads configuration files upon startup.更新Dockerfile以将conf中的文件复制到 NGIX 在启动时加载配置文件的容器中。 Add the following line into Dockerfile after the line FROM ngix (note: line may vary but should be obvious its using ngix as base image): COPY conf {INSERT RELATIVE PATH TO CONF PARENT FOLDER}FROM ngix行之后将以下行添加到Dockerfile中(注意:行可能会有所不同,但使用ngix作为基础映像应该很明显): COPY conf {INSERT RELATIVE PATH TO CONF PARENT FOLDER}

This will copy your local configuration file into the container upon creation which NGIX will load upon startup.这将在创建时将您的本地配置文件复制到容器中,NGIX 将在启动时加载该容器。

Note : There are other solutions that support configuration changes without rebuilding the container.注意:还有其他解决方案支持配置更改而不重建容器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何防止 owasp/modsecurity Docker 容器覆盖我的 nginx.conf - How do I prevent owasp/modsecurity Docker container from overwriting my nginx.conf 当我尝试安装卷时,为什么Docker无法打开nginx.conf? - Why does Docker fail to open nginx.conf when I try to mount a volume? 如何让ngnix运行在docker重新加载nginx.conf配置 - How to get ngnix running in docker to reload nginx.conf configuration 如何将环境变量传递给docker中的nginx.conf文件? - How to pass environment variable to nginx.conf file in docker? docker nginx - 尝试为 ZEE434023CF849D7DFB274ZF6BZ 添加卷时,不要启动 go - docker nginx - doen't go up when trying to add volumes for nginx.conf / default.conf 运行独立 docker 容器时,在 /etc/nginx/conf.d/nginx.conf 上游中找不到主机 - host not found in upstream in /etc/nginx/conf.d/nginx.conf when running standalone docker containers 更改 docker 内的 nginx.conf 文件 - Change nginx.conf file inside docker 如何隐藏 nginx.conf 授权凭据? - How to hide nginx.conf authorization credentials? 如何创建我的nginx.conf - How to create my nginx.conf Nginx docker - 基本的 nginx.conf 文件接受 Z0E8433F9A404F1263BA601C14B0Z0 - Nginx docker - basic nginx.conf file to accept HTTPS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM