Linux based (nginx) php web app url rewrite not working

Marianne Wurlitzer 26 Reputation points
2021-08-25T22:11:24.983+00:00

I can rewrite URLs on windows based web apps by placing a web.config file like this in the /site/wwwroot dir

<configuration>  
    <system.webServer>  
        <rewrite>  
            <rules>  
                <rule name="rule1" stopProcessing="true">  
                    <match url="123.html"/>  
                    <action type="Rewrite" url="abc.php"  appendQueryString="true" />  
                </rule>  
            </rules>  
        </rewrite>  
    </system.webServer>  
</configuration>  
 

However when I create a linux based wed app like this:

126474-azure-linux-url-rewrite.jpg

the web.config file is ignored. I have also tried a .htaccess file with no success but I not surprised because web app is running on top of nginx

The question is: **How do I setup URL rewrites for linux based (nginx) web app ??? **

Thank you.

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,930 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ryan Hill 30,281 Reputation points Microsoft Employee Moderator
    2021-08-26T19:32:31.737+00:00

    Hi @Marianne Wurlitzer ,

    To answer your question:

    How do I setup URL rewrites for linux based (nginx) web app ???

    ...please have a look at https://www.nginx.com/blog/converting-apache-to-nginx-rewrite-rules/. I did want to call out a couple of things though. PHP|8 images do utilize nginx/php-fpm in which case you won't be able to use .htaccess; however, PHP|7.4 still utilizes Apache for the underlying webserver, in which case using a .htaccess file would apply. Just make sure your .htaccess is in the root directory of your app.

    I did confirm this after creating a new app service with PHP|7.4 and checked the running processes through SSH.

    126911-image.png

    126886-image.png


1 additional answer

Sort by: Most helpful
  1. Ytowait Pvt Ltd 1 Reputation point
    2022-09-10T17:43:20.613+00:00

    inginx 404 Not Found nginx/1.14.2 error on our admin panel in PHP 8 codeigneter
    Hello Friends,
    We have a Dynamic website with admin panel hosted in webapp with php 8 and mysql. My website front end is up and running, but the admin panel is not opening. Getting inginx 404 Not Found nginx/1.14.2 error.

    we have tried below steps almost 20 times, raised tickets , but still no luck. Please help.

    Step 1: Use the SSH

    Navigate to your App Service via the Azure Portal. Under the Development Tools section, select SSH then Go -->

    Step 2: Modifying the default site config:

        You will want to make a copy of the existing configuration and place the file inside the "/home/site" directory.  
           cp /etc/nginx/sites-available/default  /home/site/default  
    

    Step 3: Update default file:

        Once copied, edit the /home/site/default file and update the section below:  
    
    server {  
    
            # Section Excluded  
    
        location /Adminsandy90637359547416415345/ {  
                 index  index.php index.html index.htm hostingstart.html;  
                try_files $uri $uri/ /index.php?$args;  
           }  
    
            location / {  
                 index  index.php index.html index.htm hostingstart.html;  
                try_files $uri $uri/ /index.php?$args;  
           }  
          # Section Excluded  
       }  
    

    Step 4: Creating the custom "startup" script

         You will now need to create a custom startup script and save the file as /home/site/startup.sh  
    

    Step 5: Overriding the existing /etc/nginx/sites-available/default file with the /home/site/default file. And then Reloading the NGINX service to make the updates take effect.

    !/bin/bash

    cp /home/site/default /etc/nginx/sites-available/default
    service nginx reload

    Step 6: Updating the application settings

    Navigate back to your App Service via the Azure Portal. Under the "Settings" section, select "Configuration".
    Go over to the "General Settings" section of the Configuration blade.
    For the "Startup Command" enter the following: /home/site/startup.sh


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.