Question
How to make a Wordpress subdomain on Nginx with SSL?
I created a new droplet (Ubuntu 16.04), and successfully went through all stages of setting up the LEMP stack and Let’s Encrypt. Wordpress is supposedly ready to start the install process.
My intended setup is to have /var/www/html serving page.com, and /var/www/html/blog (where Wordpress is) serving blog.page.com.
CNAMES are already configured for www and blog. Let’s Encrypt was configured with page.com, www.page.com and blog.page.com, and right now there are 2 nginx config files, default and blog.page.com - both with aliases on /etc/nginx/enabled-sites, and with nginx -t giving it an OK.
However, all configurations for nginx so far are only leading me to the “Welcome to Nginx” page in both page.com and blog.page.com, and I’m not being able to find out what is going on. If I try to access anything other than the base page, it 404’s, even though the files are all there on /var/www/html. Here’s the current content of default and blog.page.com after quite a few tries moving stuff:
default:
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name page.com www.page.com;
return 301 https://$server_name$request_uri;
root /var/www/html;
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 ~ /.well-known {
allow all;
}
}
server {
# SSL configuration
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
include snippets/ssl-page.com.conf;
include snippets/ssl-params.conf;
}
blog.page.com:
server {
# Server subdomain host
server_name blog.page.com;
# Server port
listen 80;
listen [::]:80;
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;
}
location / {
return 301 https://blog.page.com$request_uri;
try_files $uri $uri/ /index.php$is_args$args;
}
index index.php
# Server subdomain root folder
root /var/www/html/blog;
# Custom locations and settings
location ~ \.php$ {
fastcgi_pass unix:/var/run/php7.0-fpm.sock;
include snippets/fastcgi-php.conf;
}
}
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.
×