简体   繁体   English

修改nginx.conf为Azure App Linux服务

[英]Modifying nginx.conf for Azure App Linux Service

I am deploying a ReactJS application in Azure App Service that runs on Linux container.我在 Linux 容器上运行的 Azure 应用服务中部署一个 ReactJS 应用程序。 The ReactJS application has router. ReactJS 应用程序有路由器。 The refresh of internal pages failing due to the ReactJS routing.由于 ReactJS 路由,内部页面刷新失败。 As per React-router and nginx , I can solve this problem by adding following block in nginx.conf根据React-router 和 nginx ,我可以通过在 nginx.conf 中添加以下块来解决这个问题

location / {
  try_files $uri /index.html;
}

Now my problem is that how can I modify the nginx.conf inside the Azure App Linux container?现在我的问题是如何修改 Azure App Linux 容器内的 nginx.conf? I tried to copy to /home/site.我试图复制到/home/site。 It did not work.那没起效。 It always taking nginx.conf from /etc/nginx.它总是从 /etc/nginx 中获取 nginx.conf。 If I replace that /etc/nginx/nginx.conf with my own version, it will be overwritten on next reboot.如果我将 /etc/nginx/nginx.conf 替换为我自己的版本,它将在下次重启时被覆盖。

Is there anyway I can use my own nginx.conf?无论如何我可以使用我自己的 nginx.conf 吗? or should I create a custom container to solve it?还是我应该创建一个自定义容器来解决它?

You can actually modify your nginx configuration via the startup command of your app service.您实际上可以通过应用服务的启动命令修改您的 nginx 配置。

  • SSH into your app service. SSH 进入您的应用服务。

  • Copy over the default nginx configuration file to your home directory:将默认的 nginx 配置文件复制到您的主目录:

     cp /etc/nginx/sites-available/default /home/site/nginx.conf
  • Modify the copied over nginx configuration file /home/site/nginx.conf and include your custom configuration.修改复制过来的 nginx 配置文件/home/site/nginx.conf并包含您的自定义配置。

     vi /home/site/nginx.conf
  • Create a bash file /home/site/startup.sh with the following contents:创建一个 bash 文件/home/site/startup.sh ,内容如下:

     cp /home/site/nginx.conf /etc/nginx/sites-available/default service nginx reload
  • Set your app service startup command to /home/site/startup.sh .将您的应用服务启动命令设置为/home/site/startup.sh

During startup your app service will overwrite the default nginx configuration and reload the nginx service.在启动期间,您的应用服务将覆盖默认的 nginx 配置并重新加载 nginx 服务。 It's not the most maintainable solution but it works.它不是最易于维护的解决方案,但它确实有效。

You can not modify the nginx.conf.您不能修改 nginx.conf。 Since you're inside a Microsoft docker container, you will not be able to change that.由于您位于 Microsoft docker 容器中,因此您将无法更改它。

Any files or directories outside of the /home directory, will not be persisted between site recycles. /home 目录之外的任何文件或目录都不会在站点回收之间保留。 This can impact you in a couple of different ways.这可能会以几种不同的方式影响您。 You don't have access to change that since it is locked down under the Azure sandbox.您无权更改它,因为它被锁定在 Azure 沙箱下。

https://docs.microsoft.com/en-us/archive/blogs/waws/things-you-should-know-web-apps-and-linux#CIFS https://docs.microsoft.com/en-us/archive/blogs/waws/things-you-should-know-web-apps-and-linux#CIFS

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

相关问题 在 Elastic Beanstalk 上更改 nginx.conf? - Change nginx.conf on Elastic Beanstalk? 无法从 K8 集群编辑 nginx.conf 文件 - unable to edit nginx.conf file from K8 cluster Azure 应用服务(Linux Nginx)文件上传错误413(Payload Too Large) - Azure App service (Linux Nginx) file upload error 413 (Payload Too Large) nginx:[emerg] 在 /etc/nginx/nginx.conf:11 的上游“udagram-users:8080”中找不到主机 - nginx: [emerg] host not found in upstream "udagram-users:8080" in /etc/nginx/nginx.conf:11 Azure 应用服务 linux 忽略自定义命令 - Azure app service linux custom command ignored 在 Azure 上使用 PM2 运行 nextjs 时出错 在 Linux 上应用服务 - Error running nextjs with PM2 on Azure App Service on Linux 使用 Linux 在 Azure App Service 上哪里可以找到 coredump? - Where to find coredump on Azure App Service using Linux? 在 Azure linux 应用程序服务上执行 sudo 命令作为启动的一部分 - Execute sudo commands as part of startup on Azure linux app service 如何配置 Nginx 仅在 Azure App Service 上为 wordpress 服务 https - How to configure Nginx to serve https only for wordpress on Azure App Service Azure Linux 上的应用服务 - Static 文件内容未更新 - Azure App Service on Linux - Static File Content not updated
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM