Preface:First, let me briefly explain why we are using the HTTPS protocol now: In fact, the biggest reason for using the HTTPS protocol is that the HTTP protocol is not secure, because HTTP data transmission is: plain text transmission data , that is, when the client enters the username and password, they will be displayed. The HTTPS protocol, on the other hand, uses ciphertext to transmit data , which means that data will be encrypted during transmission.
Encryption algorithm:
1. Introduction to HTTPSHTTPS actually consists of two parts: HTTP + SSL/TLS, which means that a module for processing encrypted information is added to HTTP. Information transmission between the server and the client will be encrypted via TLS, so the transmitted data is encrypted data. HTTPS protocol principle:
2. Nginx implements HTTPS website settings1. Install Nginx[root@Nginx ~]# yum -y install pcre-devel zlib-devel popt-devel openssl-devel openssl [root@Nginx ~]# wget http://www.nginx.org/download/nginx-1.18.0.tar.gz [root@Nginx ~]# ls anaconda-ks.cfg nginx-1.18.0.tar.gz [root@Nginx ~]# tar zxf nginx-1.18.0.tar.gz -C /usr/src/ [root@Nginx ~]# cd /usr/src/nginx-1.18.0/ [root@Nginx nginx-1.18.0]# useradd -M -s /sbin/nologin nginx [root@Nginx nginx-1.18.0]# ./configure \ --prefix=/usr/local/nginx \ --user=nginx \ --group=nginx \ --with-file-aio \ --with-http_stub_status_module \ --with-http_gzip_static_module \ --with-http_flv_module \ --with-http_ssl_module \ --with-pcre && make && make install [root@Nginx nginx-1.18.0]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ [root@Nginx nginx-1.18.0]# cd [root@Nginx ~]# nginx [root@Nginx ~]# netstat -anpt | grep 80 2. Create a server certificate key file[root@Nginx ~]# openssl genrsa -des3 -out server.key 1024 ... Enter pass phrase for server.key: # Enter passwordVerifying - Enter pass phrase for server.key: # Confirm password 3. Create an application file for the server certificate[root@Nginx ~]# openssl req -new -key server.key -out server.csr Enter pass phrase for server.key: # Enter the password you created earlier... Country Name (2 letter code) [XX]:CN # Country code. China enters CN State or Province Name (full name) []:BeiJing # Full name of the province. PinyinLocality Name (eg, city) [Default City]:BeiJing # Full name of the city. PinyinOrganization Name (eg, company) [Default Company Ltd]:Coco # Company English nameOrganizational Unit Name (eg, section) []: # You can leave it blankCommon Name (eg, your name or your server's hostname) []:www.Coco.com # Domain nameEmail Address []:[email protected] # Email address. Feel free to fill in... A challenge password []: # This is optional An optional company name []: # This is optional Back up a server key file [root@Nginx ~]# cp server.key server.key.org Remove file password [root@Nginx ~]# openssl rsa -in server.key.org -out server.key Enter pass phrase for server.key.org: # 4. Generate certificate files[root@Nginx ~]# openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt Signature ok subject=/C=CN/ST=BeiJing/L=BeiJing/O=Coco/CN=www.Coco.com/[email protected] Getting Private key 5. Modify the Nginx main configuration file[root@Nginx ~]# mkdir -p /usr/local/nginx/conf/ssl [root@Nginx ~]# cp server.crt server.key /usr/local/nginx/conf/ssl/ [root@Nginx ~]# vim /usr/local/nginx/conf/nginx.conf server { listen 443; # Listening port ssl on; # Enable SSL ssl_certificate ssl/server.crt; # PS: I use a relative path here. You can use an absolute path ssl_certificate_key ssl/server.key; # The system will look for server_name www.Coco.com in the /usr/local/nginx/conf/ directory; # The domain name corresponding to the certificate... } [root@Nginx ~]# nginx -s reload # Restart Nginx service Verification: Visit the domain name you just set Implement the redirection of client access from
Misconfiguration: There is no logical problem in opening multiple ports in the same Problem : When the client accesses server { listen 80; listen 443; server_name www.Coco.com; root html; index index.html index.htm; rewrite ^(.*)$ https://$host$1 permanent; } Correct configuration:
[root@Nginx ~]# vim /usr/local/nginx/conf/nginx.conf server { listen 80; server_name www.Coco.com; rewrite ^(.*)$ https://$host$1 permanent; ... } server { listen 443; ssl on; ssl_certificate ssl/server.crt; ssl_certificate_key ssl/server.key; server_name www.Coco.com; ... } [root@localhost ~]# nginx -s reload Verification: Visit This concludes this article about the steps to set up an HTTPS website based on Nginx. For more information about Nginx HTTPS website settings, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Sample code for implementing mobile expansion and collapse effects with pure CSS3
>>: Do you know the common MySQL design errors?
Insert data into mysql database. Previously commo...
MySQL advantage: Small size, fast speed, low tota...
Mysqldump is used for logical backup in MySQL. Al...
Database read-write separation is an essential an...
MySQL server has gone away issue in PHP 1. Backgr...
This article shares with you the solution to the ...
There are many articles about MySQL installation ...
1. Introduction to mysqldump mysqldump is a logic...
So which one of these formats, GIF, PNG, and JPG,...
Generally, on national days of mourning, days of ...
This article shares the specific code of using ca...
This article shares the specific code of Vue+Webs...
When the scale of Docker deployment becomes large...
The Docker package is already included in the def...
Table of contents 1 Review 2 Five strategies for ...