I really do not know why my nginx configuration does not work for www.
My configuration is:
server {
listen 80;
server_name postimg.cz www.postimg.cz;
return 301 https://$server_name$request_uri;
}
server {
listen 443;
server_name postimg.cz;
# SSL Configuration
ssl_certificate /etc/letsencrypt/live/postimg.cz/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/postimg.cz/privkey.pem;
ssl_session_cache shared:SSL:10m;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GC>
ssl_prefer_server_ciphers on;
# See https://hstspreload.org/ before uncommenting the line below.
# add_header Strict-Transport-Security "max-age=15768000; preload;";
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header Content-Security-Policy "frame-ancestors 'self'";
add_header X-Frame-Options DENY;
add_header Referrer-Policy same-origin;
root /var/www/postimg.cz;
# Disable access to sensitive application files
location ~* (app|content|lib)/.*\.(po|php|lock|sql)$ {
return 404;
}
location ~* composer\.json|composer\.lock|.gitignore$ {
return 404;
}
location ~* /\.ht {
return 404;
}
# Image not found replacement
location ~* \.(jpe?g|png|gif|webp)$ {
log_not_found off;
error_page 404 /content/images/system/default/404.gif;
}
# CORS header (avoids font rendering issues)
location ~* \.(ttf|ttc|otf|eot|woff|woff2|font.css|css|js)$ {
add_header Access-Control-Allow-Origin "*";
}
# PHP front controller
location / {
index index.php;
try_files $uri $uri/ /index.php$is_args$query_string;
}
# Single PHP-entrypoint (disables direct access to .php files)
location ~* \.php$ {
internal;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
}
But when I go to http://www.postimg.cz it won't redirect to https://postimg.cz why is that? Can you help me with it?
Server: Ubuntu Server 20.04
EDIT // Tried also this, does not work either:
server {
listen 80;
server_name www.postimg.cz postimg.cz;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name www.postimg.cz;
ssl_certificate /etc/letsencrypt/live/www.postimg.cz/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.postimg.cz/privkey.pem;
return 301 https://postimg.cz$request_uri;
}
server {
listen 443 ssl;
server_name postimg.cz;