Problem installing wordpress on subdomain (nginx / ubuntu)

December 6, 2017 64 views
Nginx WordPress DNS LEMP Ubuntu 16.04

Hi,

I've been trying to configure my single droplet to host two different website on two different domain, where one of them is a subdomain:

  1. My homepages (static - home/about/contact etc)
  2. Blog (Dynamic - Wordpress)

I'm using Nginx and have the following config files

Main - example.com

server {
        listen 443 default_server;
        listen [::]:443 default_server;

        root /var/www/example.com.au;
        index index.html;

        ssl on;
        ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;


        server_name example.com www.example.com;
        location / {     try_files $uri $uri/ =404;
 }
 }

server {
       listen 0.0.0.0:80;
       server_name example.com www.example.com;
       rewrite ^ https://$host$request_uri? permanent;
}

Subdomain - blog.example.com

server {
listen 80;
listen [::]:80;
server_name blog.example.com www.blog.example.com;
return 301 https://blog.example.com$request_uri;

root /var/www/blog.example.com;

index index.php index.html index.htm;

location / {
try_files $uri $uri/ =404;
}

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}

location ~ /\.ht {
deny all;
}

location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; allow all; }
location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
log_not_found off;
}

The main site is working, but when I try to access the sub domain I get greeted by an error message saying that "blog.example.com's server DNS address could not be found".

I can Ping and nslookup the server using the subdomain address (blog.example.com) and it returns the IP-address of my server.

I suspect that I've done something wrong with my DNS records but I can't figure out what that might be. I've set up CNAME records, A records, and Wildcard records(*.example.com) for my subdomain.

Has anybody had this problem and if so, how were you able to resolve it?

Thanks!

Be the first one to answer this question.