Nginx configuration HTTPS protocol

Full HTTPS name

HTTPS (full name: Hypertext Transfer Protocol Secure) is an HTTP channel aimed at security. On the basis of HTTP, it ensures the security of the transmission process through transmission encryption and identity authentication. HTTPS adds SSL on the basis of HTTP, and the security basis of HTTPS is SSL, so the detailed content of encryption requires SSL. HTTPS has a different default port than HTTP and an encryption/authentication layer (between HTTP and TCP). The system provides authentication and encrypted communication methods. It is widely used in security-sensitive communications on the World Wide Web, such as transaction payments.

HTTPS has features

  • Content encryption: using hybrid encryption technology, the middleman cannot directly view the plaintext content
  • Verify identity: through certificate authentication, the client accesses its own server
  • Protect data integrity: prevent the transmitted content from being impersonated or tampered by the middleman

 Nginx configuration

[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;															# 监听端口
    ssl on;																# 开启 SSL
    ssl_certificate ssl/server.crt;										# PS:我这里是相对路径. 你们可以使用绝对路径
    ssl_certificate_key ssl/server.key;									# 系统会在 /usr/local/nginx/conf/ 目录中寻找
    server_name  www.cuplayer.com;											# 证书对应的域名
    ...
}
[root@Nginx ~]# nginx -s reload											# 重启 Nginx 服务

Separate port 80 from port 443: 

[root@Nginx ~]# vim /usr/local/nginx/conf/nginx.conf
server {
    listen 80;
    server_name  www.cuplayer.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.cuplayer.com;
    ...
}
[root@localhost ~]# nginx -s reload

  My Popular Article Recommendations

Guess you like

Origin blog.csdn.net/suny2020/article/details/127790014
Recommended