1

I'm trying to setup a nginx web server with one domain and one subdomain (example.com and download.example.com).

server {
    listen 80;
    listen [::]:80;

    root /var/www/html;

    index index.html index.htm index.nginx-debian.html;

    server_name example.com;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot

    if ($scheme != "https") {
        return 301 https://$host$request_uri;
    } # managed by Certbot

}

server {
    listen 80;
    listen [::]:80;

    root /var/www/download;

    index index.html index.htm index.nginx-debian.html;

    server_name download.example.com;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }

    #listen 443 ssl; # managed by Certbot
    #ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
    #ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
    #include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot

    #if ($scheme != "https") {
    #   return 301 https://$host$request_uri;
    #} # managed by Certbot

}

I can access example.com, but I can't access subdomain.example.com.

Logs: Sep 16 19:53:32 vps456536 systemd[1]: Starting A high performance web server and a reverse proxy server... Sep 16 19:53:32 vps456536 systemd[1]: nginx.service: Failed to read PID from file /run/nginx.pid: Invalid argument Sep 16 19:53:32 vps456536 systemd[1]: Started A high performance web server and a reverse proxy server. DNS: $TTL 3600 @ IN SOA dns200.anycast.me. tech.ovh.net. (2017091608 86400 3600 3600000 300) IN NS dns200.anycast.me. IN NS ns200.anycast.me. IN MX 1 mx1.mail.ovh.net. IN MX 100 mx3.mail.ovh.net. IN MX 5 mx2.mail.ovh.net. IN A SOME_IP IN AAAA SOME_IP IN TXT "1|example.com" 600 IN TXT "v=spf1 include:mx.ovh.com ~all" _autodiscover._tcp IN SRV 0 0 443 mailconfig.ovh.net. _imaps._tcp IN SRV 0 0 993 ssl0.ovh.net. _submission._tcp IN SRV 0 0 465 ssl0.ovh.net. autoconfig IN CNAME mailconfig.ovh.net. autodiscover IN CNAME mailconfig.ovh.net. ftp IN CNAME example.com. imap IN CNAME ssl0.ovh.net. mail IN CNAME ssl0.ovh.net. pop3 IN CNAME ssl0.ovh.net. smtp IN CNAME ssl0.ovh.net. www IN MX 1 mx1.mail.ovh.net. www IN MX 100 mx3.mail.ovh.net. www IN MX 5 mx2.mail.ovh.net. www IN A SOME_IP www IN AAAA SOME_IP www IN TXT "l|pl" www IN TXT "3|welcome"

Jqmey
  • 21
  • 3
  • More details. Log entries, error messages, DNS configuration. – Sven Sep 16 '17 at 18:03
  • @Sven added logs and dns configuration. – Jqmey Sep 16 '17 at 18:17
  • For starters, I don't see any DNS entry for `download.example.com`. Please also add the access log and tell us what "can't access ...." means for you. – Sven Sep 16 '17 at 18:20
  • @Sven `INET_E_RESOURCE_NOT_FOUND`. I don't have an access log. – Jqmey Sep 16 '17 at 18:30
  • What does that even mean? Context. Please read [How to ask better questions on Serverfault](http://meta.serverfault.com/questions/3608/how-can-i-ask-better-questions-on-server-fault) – Sven Sep 16 '17 at 18:32
  • @Sven on Chrome I get an error: `This site can’t be reached download.jqmey.net.pl’s server DNS address could not be found. Search Google for download.example.com ERR_NAME_NOT_RESOLVED` – Jqmey Sep 16 '17 at 18:44

1 Answers1

4

Add an A record or CNAME for download.example.com to your DNS zone. Just defining a vhost in nginx is not sufficient for it to be found by clients, naturally.

Sven
  • 97,248
  • 13
  • 177
  • 225