简体   繁体   中英

Modifying nginx.conf for Azure App Linux Service

I am deploying a ReactJS application in Azure App Service that runs on Linux container. The ReactJS application has router. The refresh of internal pages failing due to the ReactJS routing. As per React-router and nginx , I can solve this problem by adding following block in 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? I tried to copy to /home/site. It did not work. It always taking nginx.conf from /etc/nginx. If I replace that /etc/nginx/nginx.conf with my own version, it will be overwritten on next reboot.

Is there anyway I can use my own 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.

  • SSH into your app service.

  • Copy over the default nginx configuration file to your home directory:

     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.

     vi /home/site/nginx.conf
  • Create a bash file /home/site/startup.sh with the following contents:

     cp /home/site/nginx.conf /etc/nginx/sites-available/default service nginx reload
  • Set your app service startup command to /home/site/startup.sh .

During startup your app service will overwrite the default nginx configuration and reload the nginx service. It's not the most maintainable solution but it works.

You can not modify the nginx.conf. Since you're inside a Microsoft docker container, you will not be able to change that.

Any files or directories outside of the /home directory, will not be persisted between site recycles. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM