CentOS8.0 nginx ssl访问

安装.

[root@localhost ~]# dnf install nginx -y

切换到nginx主目录

[root@localhost ~]# cd /etc/nginx/

生成ssl 密钥

[root@localhost ~]# openssl req -new -newkey rsa:4096 -nodes -keyout server.key -out server.csr

生产自签名证书

[root@localhost ~]# openssl req -newkey rsa:4096 -nodes -keyout server.key -x509 -days 365 -out server.crt

备份nginx.conf

[root@localhost ~]# cp -p nginx.conf nginx.conf.bak

配置nginx.conf

[root@localhost ~]# vim nginx.conf

把这段去掉#号
server {
        listen       443 ssl http2 default_server;
        listen       [::]:443 ssl http2 default_server;
        server_name  www.jnds.com; (域名)
        root         /usr/share/nginx/html; (网页存放路径)

        ssl_certificate "/etc/nginx/server.crt"; (证书存放路径)
        ssl_certificate_key "/etc/nginx/server.key"; (密钥存放路径)
        ssl_session_cache shared:SSL:1m;
        ssl_session_timeout  10m;
        ssl_ciphers PROFILE=SYSTEM;
        ssl_prefer_server_ciphers on;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

重启服务

[root@localhost ~]# systemctl restart nginx

关闭防火墙

[root@localhost ~]# systemctl stop firewalld

[root@localhost ~]# setenforce 0

你可能感兴趣的:(Linux,CentOS8.0,nginx,ssl访问,有点简陋见谅)