I am trying to create a single Nginx config for multiple hosts based on a directory. I followed a guide which seems to work well with standard HTTP setup but when I add the HTTPS 301 redirect, I can an error "invalid redirect". Any ideas on this? Below is my config. Tx
server {
listen x.x.x.x:80;
server_name ~^(?<sname>.+?).domain.com$;
return 301 https://$server_name$request_uri;
}
server {
listen x.x.x.x:443 ssl default_server;
server_name ~^(?<sname>.+?).domain.com$;
root /var/web/$sname;
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
ssl_certificate /etc/letsencrypt/live/wildcard.domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/wildcard.domain.com/privkey.pem;
access_log /var/log/nginx/$sname-access.log;
error_log /var/log/nginx/wildcard-error.log debug;
error_page 404 /index.php;
sendfile off;
location ~ \.php {
include fastcgi.conf;
#fastcgi_index index.php;
include cors_support;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
}
location ~ /\.ht {
deny all;
}
location /.well-known {
root /var/www/html;
}
}