Azure web app NGINX configuration - Redirect www to non www

Nuno Vicente 40 Reputation points
2023-07-19T23:35:24.6+00:00

Need some help. With the following configuration on NGINX the browser keeps throwing the error "too many redirects". All the examples I see points to this approach. Thanks in advance.

server {
	listen 8080;
	listen [::]:8080;
	root /home/site/wwwroot;
	index  index.php index.html index.htm;
	server_name www.domain-example.com;
	return 301 $scheme://domain-example.com$request_uri;
	port_in_redirect off;
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,933 questions
Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
1,173 questions
0 comments No comments
{count} votes

Accepted answer
  1. Andriy Bilous 11,821 Reputation points MVP Volunteer Moderator
    2023-07-20T06:50:16.87+00:00

    Hello @Nuno Vicente

    Try to add another server block to handle requests for "domain-example.com" after redirection.
    Without this, requests to "domain-example.com" might cause a redirect loop.

    server {
        listen 8080;
        listen [::]:8080;
        server_name www.domain-example.com;
        return 301 $scheme://domain-example.com$request_uri;
    }
    
    server {
        listen 8080;
        listen [::]:8080;
        root /home/site/wwwroot;
        index index.php index.html index.htm;
        server_name domain-example.com;
    }
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most 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.