Site resolves to www in Firefox and without in Chrome
I am guessing this is being caused by my nginx configuration, however I can not quite figure out how to troubleshoot in order to resolve.
I am using Ubuntu 20.04 with a LEMP stack to host a wordpress installation. Everything works fine except this quirk, which is that if I type in the site's URL into Chrome, the site will resolve to 'https://example.com' and everything on the site loads fine.
However, in Firefox if I type in the site's URL it will resolve to 'https://www.example.com', which would be fine except that certain icons on the site will now not load, are not show and are replaced by a square box.
Below is the nginx configuration I am using:
server {
listen 80;
server_name www.{{ domain_name }}{{ tld }} {{ domain_name }}{{ tld }};
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name www.{{ domain_name }}{{ tld }};
ssl_certificate /etc/letsencrypt/certs/fullchain_{{ domain_name }};
ssl_certificate_key /etc/letsencrypt/keys/{{ domain_name }}.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4:HIGH:!MD5:!aNULL:!EDH:!AESGCM;
# ssl_ecdh_curve secp521r1;
root /home/{{ domain_name }}/public_html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?q=$uri$args;
}
# return 301 https://www.$server_name$request_uri;
location ~ \.php$ {
# Basic
try_files $uri =404;
fastcgi_index index.php;
# Create a no cache flag
set $no_cache ;
# Don't ever cache POSTs
if ($request_method = POST) {
set $no_cache 1;
}
# Admin stuff should not be cached
if ($request_uri ~* /(wp-admin/|wp-login.php)) {
set $no_cache 1;
}
# WooCommerce stuff should not be cached
if ($request_uri ~* /store.*|/cart.*|/my-account.*|/checkout.*|/addons.*) {
set $no_cache 1;
}
# If we are the admin, make sure nothing
# gets cached, so no weird stuff will happen
if ($http_cookie ~* wordpress_logged_in_) {
set $no_cache 1;
}
# Cache and cache bypass handling
fastcgi_no_cache $no_cache;
fastcgi_cache_bypass $no_cache;
fastcgi_cache microcache;
fastcgi_cache_key $scheme$request_method$server_name$request_uri$args;
fastcgi_cache_valid 200 60m;
fastcgi_cache_valid 404 10m;
fastcgi_cache_use_stale updating;
# General FastCGI handling
fastcgi_pass unix:/var/run/php/{{ domain_name }}.sock;
fastcgi_pass_header Set-Cookie;
fastcgi_pass_header Cookie;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_intercept_errors on;
include fastcgi_params;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|woff|ttf|svg|otf)$ {
expires 30d;
add_header Pragma public;
add_header Cache-Control public;
access_log off;
}
}