Reputation: 25
I am on AWS Ubuntu server and had my domain verified and a certificate from certificate manager, but I couldn't manage to use it on my server, seems like it is for external traffic. Anyhow, I went with a letsencrypt guide from https://hackernoon.com/easy-lets-encrypt-certificates-on-aws-79387767830b
and then went into my etc/nginx/sites-available and edited mysite.com's virtual server file. The settings are below. I have two subdomains, asdf.mysite.com asdf2.mysite.com and the main one has wordpress. Now, the main site redirects to the first subdomain asdf.mysite.com. How do I get https on my nginx server and have it direct to the main site?
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
ssl_certificate /etc/letsencrypt/live/mysite.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mysite.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/mysite.com/chain.pem;
server_name mysite.com www.mysite.com;
root /var/www/wordpress;
index index.php index.html index.htm;
client_max_body_size 100M;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_connect_timeout 300s;
fastcgi_param PHP_VALUE "upload_max_filesize = 50M \n post_max_size=51M";
fastcgi_read_timeout 300s;
fastcgi_send_timeout 300s;
}
}
Upvotes: 0
Views: 271
Reputation: 15557
It isn't "redirects" to your first subdomain. Looks like this subdomain becomes the default server listening on plain HTTP port 80 after you changed your configuration for this one. Read this article for details if you're interested. If you explicily type https://www.yourdomain.com
in the browser address bar, I think you'll get your site back. You need to add another server
block to this configuration file that will do HTTP to HTTPS redirection for your main site:
server {
listen 80;
listen [::]:80;
server_name mysite.com www.mysite.com;
return 301 https://$host$request_uri;
}
Upvotes: 1