Skip to content

Nginx 配置空头主机

生成自签名证书

生成key

shell
cd /usr/local/nginx/conf/ssl
openssl genrsa -des3 -out none.key 1024
# 生成时必须输入4位及以上密码

移除密码

shell
mv none.key xxx.key
openssl rsa -in xxx.key -out none.key
rm -rf xxx.key

生成证书请求文件

shell
openssl req -new -key none.key -out none.csr

根据请求文件生成crt证书

shell
sudo openssl x509 -req -days 3650 -in none.csr -signkey none.key -out none.crt

Nginx 配置

!> 插入以下443端口配置并在80和443端口分别插入 return 500;

nginx
server
    {
        listen 443 ssl http2 default_server reuseport;
        #listen [::]:443 ssl http2;
        server_name _;
        index index.html index.htm index.php;
        root  /home/wwwroot/default;

        return 500;

        ssl_certificate /usr/local/nginx/conf/ssl/none.crt;
        ssl_certificate_key /usr/local/nginx/conf/ssl/none.key;
        ssl_session_timeout 5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
        ssl_prefer_server_ciphers on;
        ssl_ciphers "TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
        ssl_session_cache builtin:1000 shared:SSL:10m;
        # openssl dhparam -out /usr/local/nginx/conf/ssl/dhparam.pem 2048
        ssl_dhparam /usr/local/nginx/conf/ssl/dhparam.pem;

    }