Posts

Showing posts from November, 2023

Remove www in the site address, 301 redirects

A redirect is to redirect site visitors from one URL to another. 301 status indicates that the redirect is permanent. Removing www from the site address is necessary primarily for SEO . Since sites with www and without for search engines are different sites with the same content. For Apache server, you need to make an entry in the .htaccess file RewriteCond %{HTTP_HOST} ^www.example.com RewriteRule ^(.*)$ http://example.com/$1 [R=301,L] For NGINX , write in the site configuration file if ($host ~* www\.(.*)) { set $host_without_www $1; rewrite ^(.*)$ http://$host_without_www$1 permanent; } $host_without_www - write like that, this is a server variable

Ways to Create Objects in JavaScript

There are several ways to create objects in JavaScript . The Object data type plays a critical role in JS . An object is an unordered set of key-value pairs. May contain other objects 1. Literal notation var someObject_1 = {}; Perhaps the most common and easiest way. Let's add properties and methods someObject_1.name = "John"; someObject_1.age = 25; someObject_1.run = function(){ console.log("run") } And now the same thing, but we will set properties and methods when creating var someObject_1 = { name: "John", age: 25, run: function(){ console.log("run"); } }; 2. Object constructor This method is not recommended for use, and it is better to use the previous one. Nevertheless, it exists. But the probability of meeting him is extremely small var someObject_2 = new Object(); We also set properties and methods var someObject_2 = { name: "Nick", age: 30, jump: function(){ conso

Configure https for Nginx

HTTPS is an advanced data transfer protocol that supports encryption. Install free ssl certificate from Lets Encrypt . Ubuntu server operating system Get a certificate sudo letsencrypt certonly -a webroot --webroot-path=/var/www/site.com/public_html -d site.com -d www.site.com Prolong sudo letsencrypt renew nginx config server { listen 80 ; server_name site.com.ru www.site.com; return 301 https://$server_name$request_uri; } server { # SSL configuration listen 443 ssl http2; listen [::]:443 ssl http2; server_name site.com www.site.com; ssl_certificate /etc/letsencrypt/live/site.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/site.com/privkey.pem; ssl_trusted_certificate /etc/letsencrypt/live/site.com/chain.pem; add_header Content-Security-Policy "img-src https: data:; upgrade-insecure-requests"; # We keep access log: access_log /var/log/nginx/site.com_access.log; # We share static and dynamic, static