1

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?

mkvs
  • 21
  • 1
  • 3

2 Answers2

6

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.

mvdgun
  • 262
  • 5
  • 15
0

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://learn.microsoft.com/en-us/archive/blogs/waws/things-you-should-know-web-apps-and-linux#CIFS

elarcoiris
  • 1,914
  • 4
  • 28
  • 30
Krystal
  • 9
  • 1