Generate SSL Key and CSR file using OpenSSL To configure HTTPS, you need the private key example.key file and the certificate example.crt file. When applying for a certificate file, you need the example.csr file. The OpenSSL command can generate the example.key file and the certificate example.csr file. CSR: Certificate Signing Request, a certificate signing request file that contains the applicant's DN (Distinguished Name) and public key information, which needs to be provided when a third-party certificate authority signs a certificate. After receiving the CSR, the certificate authority uses its root certificate private key to encrypt the certificate and generate a CRT certificate file, which contains the certificate encryption information and the applicant's DN and public key information. Key: The private key file of the certificate applicant, used in pair with the public key in the certificate. In the HTTPS "handshake" communication process, the private key is needed to decrypt the random number information sent by the client that is encrypted by the certificate public key. It is a very important file in the HTTPS encrypted communication process and is used when configuring HTTPS. Use the OpenSSl command to generate example.key and example.csr files in the current directory of the system:
The following are the meanings of the relevant fields of the above command:
After generating the csr file, provide it to the CA organization. After successful signing, you will get an example.crt certificate file. After obtaining the SSL certificate file, you can configure HTTPS in the Nginx configuration file. Configure HTTPS Basic Configuration To enable HTTPS service, in the configuration file information block (server block), you must use the ssl parameter of the listen command and define the server certificate file and private key file, as shown below: server { #ssl parameter listen 443 ssl; server_name example.com; #Certificate file ssl_certificate example.com.crt; #Private key file ssl_certificate_key example.com.key; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers HIGH:!aNULL:!MD5; #... } The certificate file will be sent as a public entity to each client connected to the server. The private key file, as a security entity, should be stored in a directory file with certain permission restrictions and ensure that the Nginx main process has access permissions. The private key file may also be placed in the same file as the certificate file, as shown below:
In this case, the read permission of the certificate file should also be restricted, so that even though the certificate and private key are stored in the same file, only the certificate will be sent to the client. The commands ssl_protocols and ssl_ciphers can be used to restrict connections to only include enhanced versions and algorithms of SSL/TLS. The default values are as follows:
Since the default values of these two commands have changed several times, it is not recommended to define them explicitly unless there are additional values that need to be defined, such as defining the DH algorithm:
Force HTTP to HTTPS Also configure a server block, listen to port 80, and add rewrite. server { listen 80; server_name server ip; rewrite ^(.*)$ https://$host$1 permanent; #Force http to https } Server configuration reference server { listen 80; server_name server ip; rewrite ^(.*)$ https://$host$1 permanent; #Force http to https } server { charset utf-8; #server encoding listen 443 ssl; #listening address server_name server ip; #domain name of the website bound to the certificate server_tokens off; #hide nginx version number #ssl configuration ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt; #public key of certificate ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key; #private key of certificate ssl_session_timeout 5m; ssl_ciphers SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers off; ssl_dhparam /etc/nginx/dhparams.pem; #Request header add_header Strict-Transport-Security max-age=63072000; add_header X-Frame-Options SAMEORIGIN; add_header Content-Security-Policy "default-src 'self' http: https: data: blob: 'unsafe-inline'" always; add_header X-Content-Type-Options nosniff; add_header X-XSS-Protection "1; mode=block"; add_header Strict-Transport-Security "max-age=31536000; includeSubdomains;"; add_header Set-Cookie "HttpOnly"; add_header Set-Cookie "Secure"; #Request Method Restrictions## Only allow these request methods ## if ($request_method !~ ^(GET|POST|DELETE|PUT|PATCH)$ ) { return 444; } #Access path matching location / { root /usr/share/nginx/html; #site directory index index.html index.htm; } location /test/ { proxy_pass http://127.0.0.1:8100/; #Forward local port 8100 } #Prohibit access to the path# location /dirdeny { # deny all; # return 403; #} #Error page configuration error_page 502 503 504 /error502.html; location = /error502.html{ root /usr/share/nginx/html; } error_page 500 /error.html; location = /error.html{ root /usr/share/nginx/html; } error_page 404 /notfind.html; location = /notfind.html{ root /usr/share/nginx/html; } } The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Implementation of fuzzy query like%% in MySQL
>>: HTML table markup tutorial (4): border color attribute BORDERCOLOR
Copy code The code is as follows: <!DOCTYPE ht...
When using the docker-maven-plugin plug-in, Maven...
MySQL binlog is a very important log in MySQL log...
1. Rounded Corners Today's web designs are con...
Preface This article mainly introduces the releva...
wedge Because the MySQL version installed on the ...
At work, we often need remote servers and often e...
CSS3 can change the color of pictures. From now o...
Preface View is a very useful database object in ...
xml <?xml version="1.0" encoding=&qu...
Intro Previously, our docker images were stored i...
Table of contents Overview 1. Simple Example 1. U...
1.watch listener Introducing watch import { ref, ...
Last time, a very studious fan asked if it was po...
Table of contents Install vim plugin manager Add ...