How do I do a 301 redirect with Azure Wordpress running Nginx?

Don Chambers 15 Reputation points
2023-01-27T04:15:18.9166667+00:00

I have an app service using the azure provided WordPress image, which uses the wordpress-alpine-php docker image, running nginx version 1.20.2. I need to redirect HTTP to HTTPS, and www to non-www, with the Azure AppService version of WordPress. There isn't much documentation on this, and nothing I have tried has worked.

My issue is similar to the one described in this question, but the solution doesn't work. The file reference in that question, /etc/nginx/sites-available/default, does not exist. The sites-available folder does not exist, but there are files named default in these two locations:

/etc/nginx/conf.d/default.conf

./etc/nginx*/http.d*/default.conf

I have seen information saying I should add the server block to nginx.conf, but there are also two versions of this file, in the following locations:

  • /etc/nginx/nginx.conf
  • /home/site/wwwroot/nginx.conf

I've tried both of them, but neither seems to work. The one under etc doesn't seem to persist a container reload. I do know about copying the correct version and then reloading nginx with a startup command, as described in this Microsoft article. This doesn't work, but I may be copying over the wrong file.

After the copy, I restart Nginx with the command service nginx reload, but I get the following error.

User's image

The article above says to use this command service nginx restart, but it gives the error below:

User's image

How can I get the redirect to work?

Is there a better way to do this with the azure app service?

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,756 questions
{count} vote

1 answer

Sort by: Most helpful
  1. ajkuma 26,131 Reputation points Microsoft Employee
    2023-02-17T13:42:29.0033333+00:00

    To benefit the community, posting an answer from offline discussions.

    Fixed the issue by implementing the startup command inside of /home/dev/startup.sh and over the configuration>>startup command.
     
    Everytime App Service is restarted, it will create this dev folder by default, so, it will initialize this file instead we created it manually.

    Thanks for your patience and cooperation @Don Chambers . To help community find the answer quickly, please click Accept Answer.

    1 person found this answer helpful.

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.