Question

Unable to get subdomains working

I’m sure this is some stupid little thing I’m missing, so I’m reluctant to post, but I don’t want to waste any more of my evening on something I can’t solve.

On my server I want to setup a staging url which will host beta features before we push them live. However, despite putting in an A record and setting up my server configurations in nginx they don’t want to work, I can only assume it’s a small thing.

I have 2 nginx server files, both are enabled.

First is custom, this is the production url with HTTPS

server {
        listen 443 ssl;
        server_name allagandata.com www.allagandata.com;

        ssl_certificate /var/www/acme/.acmephp/master/certs/allagandata.com/fullchain.pem;
        ssl_certificate_key /var/www/acme/.acmephp/master/private/allagandata.com/private.pem;

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        ssl_dhparam /var/www/acme/.acmephp/master/certs/allagandata.com/dhparam.pem;
        ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-$
        ssl_session_timeout 1d;
        ssl_session_cache shared:SSL:50m;
        ssl_stapling on;
        ssl_stapling_verify on;
        add_header Strict-Transport-Security max-age=15768000;

        root /var/www/Production/public;
        index index.php index.html index.htm;

        location / {
                try_files $uri $uri/ /index.php?$query_string;
        }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_intercept_errors on;
    }

        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;
}

The second is the staging url:

server {
        listen 80;
        server_name staging.allagandata.com;

        root /var/www/AnExiledGod/public;
        index index.php index.html index.htm;

        location / {
                try_files $uri $uri/ /index.php?$query_string;
        }

        location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
                fastcgi_intercept_errors on;
        }

        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;
}

My DNS records:

$ORIGIN allagandata.com.
$TTL 1800
allagandata.com. IN SOA ns1.digitalocean.com. hostmaster.allagandata.com. 1475025426 10800 3600 604800 1800
allagandata.com. 1800 IN NS ns1.digitalocean.com.
allagandata.com. 1800 IN NS ns2.digitalocean.com.
allagandata.com. 1800 IN NS ns3.digitalocean.com.
staging.allagandata.com. 1800 IN A 162.243.102.77
allagandata.com. 1800 IN A 162.243.102.77

I did have a CNAME record in there but it didn’t seem to do anything.

Subscribe
Share

Submit an 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.

Hi.

Make sure you enabled your server block. You should have symlink from sites-available to sites-enabled.

  1. sudo ln -s /etc/nginx/sites-available/staging /etc/nginx/sites-enables

Make sure you use corresponding file name instead of staging. When you done it

  1. sudo nginx -t

to verify configuration files.

If tests are OK, restart nginx and try again.

  1. sudo systemctl restart nginx

Learn more about Server blocks.

About DNS records. I think you can also use A record as you do now. Personally I use CNAME - subdomain @ and it works flawless

I am experiencing similar issue. We have abc.ph domain that is being managed in ClouDNS. I created a A record (subdomain) do1.abc.ph pointing to droplets’ IP. Configured the default server{} block to server_name do1.abc.ph and the location{} block was for proxy since I have a node app. nginx -t is fine but I can’t access the droplet using the subdomain