Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 910
mkvs Avatar asked Sep 08 '25 11:09

mkvs


1 Answers

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.

like image 65
mvdgun Avatar answered Sep 10 '25 02:09

mvdgun