Pulkit Sharma
Pulkit Sharma

Reputation: 262

Nginx not connecting url to application

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

Upvotes: 0

Views: 1296

Answers (1)

Rakesh Sharma
Rakesh Sharma

Reputation: 61

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.

Upvotes: 2

Related Questions