内网环境nginx配置https访问

#!/bin/sh

# create self-signed server certificate:

read -p "Enter your domain [www.example.com]: " DOMAIN

echo "Create server key..."

openssl genrsa -des3 -out $DOMAIN.key 2048

echo "Create server certificate signing request..."

SUBJECT="/C=US/ST=Mars/L=iTranswarp/O=iTranswarp/OU=iTranswarp/CN=$DOMAIN"

openssl req -new -subj $SUBJECT -key $DOMAIN.key -out $DOMAIN.csr

echo "Remove password..."

mv $DOMAIN.key $DOMAIN.origin.key
openssl rsa -in $DOMAIN.origin.key -out $DOMAIN.key

echo "Sign SSL certificate..."

openssl x509 -req -days 3650 -in $DOMAIN.csr -signkey $DOMAIN.key -out $DOMAIN.crt

1、复制以上脚本到linux服务器运行

  运行时会要求输入域名以及4次密码

2、修改nginx.config

server {
    listen 86;
    # 以下3行配置ssl,开启并指定后缀为crt与key的绝对路径
    ssl on;	
    ssl_certificate /etc/nginx/ssl/<域名>.crt;
    ssl_certificate_key /etc/nginx/ssl/<域名>.key;

    location / {
        ...
    }
}

3、重新启动ngixn

posted @ 2023-06-10 08:56  LewsKay  阅读(198)  评论(0编辑  收藏  举报