Andrew Fletcher published: 16 December 2021 (updated) 13 October 2023 1 minute read
Forcing https and www or non-www is a process that I was a custom to through .htaccess. In fact I had become very strong at managing and working my .htaccess files. However, what I had become strong in one area, I was oblivious to using other methods. My bad.
Well that was until I had to change my way. Working on an Nginx server, .htaccess was not in play. Instead, I needed to configure the /etc/nginx/sites-available directory.
For me to force SSL and www I added the following
server { listen 80; server_name codebales.com; return 301 http://www.codebales.com$request_uri; } server { listen 443 ssl; listen [::]:443 ssl; ssl_certificate /etc/ssl/certs/{project}2122.crt; ssl_certificate_key /etc/ssl/private/project}_WC_21-22_plain.key; server_name {domain}; return 301 https://www.codebales.com$request_uri; } server { listen 80; listen [::]:80; listen 443 ssl; ssl_certificate /etc/ssl/certs/Code2122.crt; ssl_certificate_key /etc/ssl/private/Code_WC_21-22_plain.key; root /var/www/html/drupal; index index.php index.html index.htm; server_name {domain}; # Redirect HTTP to HTTPS if ($scheme = http) { return 301 https://$server_name$request_uri; } location / { try_files $uri /index.php?$query_string; } location @rewrite { rewrite ^/(.*)$ /index.php?q=$1; } location ~ [^/]\.php(/|$) { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~ ^/sites/.*/files/styles/ { # For Drupal >= 7 try_files $uri @rewrite; } location ~ ^(/[a-z\-]+)?/system/files/ { # For Drupal >= 7 try_files $uri /index.php?$query_string; } }
Related articles
Andrew Fletcher
•
18 Apr 2024
No results showing for your Solr instance - solr.service: Failed with result 'exit-code'
When Solr is displaying results on the site, first step is to log in the server and check its status● solr.service - LSB: Controls Apache Solr as a Service
Loaded: loaded (/etc/init.d/solr; generated)
Active: failed (Result: exit-code) since Wed 2024-04-17 23:22:52 UTC; 6h ago
...
Andrew Fletcher
•
18 Mar 2024
Resolving CVE-2022-48624 less issue
To resolve the CVE-2022-48624 vulnerability on Ubuntu using Nginx, it's crucial to understand that the issue lies within the "less" package, not Nginx itself. The vulnerability affects "less" before version 606, where close_altfile in filename.c in less omits shell_quote calls for LESSCLOSE,...
Andrew Fletcher
•
06 Mar 2024
Terminal command to find and replace
In many terminal text editors, you use find command as reference in Terminal commands - find. How about find and replace. This action depends on the specific text editor you're using in the terminal. Here are a few common terminal text editors and how you can find and replace...