GNU/Linux >> Znalost Linux >  >> Panels >> Panels

Jak zabezpečit Nginx pomocí Let's Encrypt na Ubuntu 20.04

Zabezpečení webu běžícího s Nginx jako webový server lze provést pomocí Let’s Encrypt, a proto pro vás píšeme tento návod.

Let’s Encrypt je certifikační autorita, která poskytuje bezplatné certifikáty TLS/SSL platné po dobu 90 dnů. SSL je zkratka pro Secure Sockets Layer a SSL certifikát je digitální certifikát, který umožňuje šifrované připojení a ověření identity webu. V tomto příspěvku na blogu použijeme Certbot k získání bezplatného certifikátu SSL pro Nginx.

Instalace certifikátu Free Let’s Encrypt SSL na Ubuntu 20.04 pomocí Certbot je jednoduchý proces a měl by trvat až 10 minut. Začněme!

Předpoklady

  • Nová instalace Ubuntu 20.04
  • Uživatelská práva:uživatel root nebo uživatel bez oprávnění root s právy sudo
  • Platný záznam domény odkazující na vaši IP adresu serveru (vašedoména.com a www.vašedoména.com)

Aktualizujte systém

Než začneme s procesem instalace, musíme aktualizovat systém, abychom získali nejnovější dostupné balíčky a aktualizace.

sudo apt update -y && sudo apt upgrade -y

Instalovat webový server Nginx

Chcete-li nainstalovat webový server Nginx, proveďte následující příkazy:

sudo apt install nginx -y

Po dokončení instalace povolte a spusťte službu Nginx:

sudo systemctl enable nginx && sudo systemctl start nginx

Chcete-li zkontrolovat, zda je vše v pořádku, zkontrolujte stav služby:

sudo systemctl status nginx

Měli byste obdržet následující výstup:

root@vps:~# systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2022-02-06 19:34:56 UTC; 11s ago
       Docs: man:nginx(8)
    Process: 322857 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 322858 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 322859 (nginx)
      Tasks: 5 (limit: 4617)
     Memory: 5.0M
     CGroup: /system.slice/nginx.service
             ├─322859 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;

Vytvořit virtuálního hostitele Nginx

Než budeme pokračovat v instalaci Free Let’s Encrypt, musíme vytvořit soubor virtuálního hostitele obsahující název naší domény. Přejděte do konfiguračního adresáře Nginx a vytvořte soubor.

cd /etc/nginx/conf.d/ && sudo nano yourdomain.com.conf

Vložte následující řádky kódu.

server {
        listen 80;
        root /var/www/html;
        index  index.php index.html index.htm;
        server_name yourdomain.com;

        error_log /var/log/nginx/yourdomain.com_error.log;
        access_log /var/log/nginx/yourdomain.com_access.log;

        client_max_body_size 100M;
        location / {
                try_files $uri $uri/ /index.php?$args;
        }
}

Zkontrolujte syntaxi konfigurace Nginx, pokud je v pořádku.

nginx -t

Měli byste obdržet následující výstup:

root@vps:/etc/nginx/conf.d# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Pokud obdržíte tento výstup, můžete restartovat službu Nginx a získat přístup na svůj web.

sudo systemctl restart nginx

Nainstalovat Certbot

V tuto chvíli naše webové stránky běží nad protokolem HTTP. Instalace certifikátu Free Let’s Encrypt SSL zajistí bezpečný provoz našich webových stránek přes protokol HTTPS. Než začneme se získáním certifikátu, musíme nainstalovat python certbot pro Nginx.

sudo apt install certbot python3-certbot-nginx

Jakmile je certbot úspěšně nainstalován, můžeme pokračovat hlavním krokem v tomto tutoriálu o získání certifikátu SSL.

Získání certifikátu SSL

Chcete-li spustit certbot s pluginem Nginx specifikujícím název vaší domény, spusťte následující příkaz:

sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com

Po provedení tohoto příkazu bude několik položek, které budete muset vyplnit, jako je e-mailová adresa, dohoda o podmínkách, zda chcete sdílet svou e-mailovou adresu nebo ne, a možnosti přesměrování.

root@vps:~# sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [email protected]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: N
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for yourdomain.com
http-01 challenge for www.yourdomain.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/example.conf
Deploying Certificate to VirtualHost /etc/nginx/conf.d/example.conf

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/example.conf
Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/example.conf

Pokud je vše nastaveno tak, jak má být, certifikát se nainstaluje a obdržíte zprávu níže.

Congratulations! You have successfully enabled https://yourdomain.com and
https://www.yourdomain.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=yourdomain.com
https://www.ssllabs.com/ssltest/analyze.html?d=www.yourdomain.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/yourdomain.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/yourdomain.com/privkey.pem
   Your cert will expire on 2022-05-07. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

Nyní můžete na svůj web přistupovat zabezpečeně na adrese https://yourdomain.com

Gratulujeme! Úspěšně jste zabezpečili Nginx pomocí certifikátu Free Let’s Encrypt SSL na vašem serveru Ubuntu 20.04.

SSL certifikát si samozřejmě nemusíte instalovat sami, a pokud využíváte některou z našich služeb SSD VPS Hosting, v tom případě můžete jednoduše požádat naše zkušené správce systému, aby vám jej nainstalovali a zabezpečili váš web. Jsou k dispozici 24×7 a okamžitě se postarají o váš požadavek.

Pokud se vám líbil tento příspěvek o tom, jak zabezpečit Nginx pomocí Lets Encrypt na Ubuntu 20.04, sdílejte jej se svými přáteli na sociálních sítích pomocí tlačítek níže nebo jednoduše zanechte komentář v sekci komentářů. Děkuji.


Panels
  1. Jak nainstalovat Elgg s Nginx na Ubuntu 14.04

  2. Jak nainstalovat Elgg s Nginx na Ubuntu 18.04

  3. Jak nainstalovat Gitea s NGINX a Free Let's Encrypt SSL na Ubuntu 20.04

  1. Zabezpečte Nginx pomocí Let's Encrypt na Ubuntu 18.04 - Jak na to?

  2. Jak zabezpečit Nginx pomocí Letsencrypt na Ubuntu 20.04

  3. Jak nainstalovat Joomla s Nginx na Ubuntu 18.04

  1. Jak zabezpečit Nginx pomocí Lets Encrypt na Ubuntu 20.04 / 18.04

  2. Zabezpečte Nginx pomocí Lets Encrypt na Ubuntu 18.04

  3. Jak nainstalovat Let’s Encrypt na Ubuntu 20.04 s Apache