0

This is my nginx site-enabled file.

server {

    client_max_body_size 4G;
    server_name example.in;
    
    gzip on;
    gzip_proxied any;
    gzip_vary on;
    gzip_types application/javascript application/json text/css text/xml;
    gzip_comp_level 4;

    
location / {

        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
    }
    

     listen 443 ssl http2; # managed by Certbot
    listen [::]:443 ssl http2;
    ssl_certificate /etc/letsencrypt/live/example.in/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.in/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    
}
server {
    listen 80;
    listen [::]:80;
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name example.in www.example.in;
    return 301 https://example.in$request_uri;
}
 

When I visit, example.in site is opening properly. However when I open www.example.in, I get default nginx page. What is wrong in this configuration? I have same configuration for other domain and that works fine.

nginx -T gives below results:

nginx: [warn] conflicting server name "www.example.in" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "www.example.in" on [::]:80, ignored
nginx: [warn] conflicting server name "example.in" on [::]:443, ignored
nginx: [warn] conflicting server name "www.example.in" on [::]:443, ignored
nginx: [warn] conflicting server name "example.in" on 0.0.0.0:443, ignored
nginx: [warn] conflicting server name "www.example.in" on 0.0.0.0:443, ignored
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Pulkit Sharma
  • 264
  • 1
  • 2
  • 18
  • Check your error log. It looks like you have a duplicate `server_name` listening on port 443. – Richard Smith Apr 08 '21 at 08:09
  • @RichardSmith Is there a command for that? Can you rearrange and show answer for correct configuration? Thanks in advance – Pulkit Sharma Apr 08 '21 at 08:29
  • Use `nginx -T` (uppercase `T`) to view your entire configuration across all included files. [This solution](https://stackoverflow.com/questions/43081780/dns-records-redirect-www-to-non-www/43089681#43089681) uses the default server to redirect everything to `example.com`. – Richard Smith Apr 08 '21 at 08:36

1 Answers1

2

Your configuration looks correct. Check if there is any other nginx config file enabled under sites-enabled. Usually, a default file with the name 'default' is enabled with default server configuration, which can cause the problem. Check if that file also contains entry for www.example.in. If that's the case disable it or make the file blank.