Report this

What is the reason for this report?

[NGINX + NODEJS] Can't access www.sub.domain.com

Posted on October 27, 2014

I’ve already added a CNAME @ record in the DNS section.

Here’s my nginx vhost configs for my nodejs apps, note: I also included a www to non-www redirection block for each vhost

Subdomain

server {
    listen 80;
    server_name www.sub.domain.com;

    return 301 $scheme://sub.domain.com$request_uri;
}

server {
    listen 80;
    listen [::]:80;
    listen 443 ssl;
    
    server_name sub.comain.com;
    client_max_body_size 20m;

    ssl_certificate      /etc/nginx/server.crt;
    ssl_certificate_key  /etc/nginx/server.key;
    
    if ($scheme = http) {
        return 301 https://$server_name$request_uri;
    }

    location / {
        proxy_pass https://localhost:8080;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

Main Domain

server {
    listen 80;
    server_name www.domain.com;

    return 301 $scheme://domain.com$request_uri;
}

server {
    listen 80;
    listen [::]:80;
    
    server_name domain.com;

    location / {
        proxy_pass https://localhost:2360;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Have you added a record for www.sub.domain.com? It can be a CNAME to domain.com if they’re both hosted on the same droplet:

www.sub CNAME @

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.