大网数据广告活动
服务器运维问答

Sharing two SSL certificates with as wildcard and root domains in nginx (same server)

· 52CE 我爱测

I have purchased a wildcard certificate and a single certificate for my domain structure which is: app.example.com => single *.app.example.com => wildcard Both these routes should point to the same project directory on same serve…

问题原文

原帖链接 · senty · CC BY-SA 3.0

I have purchased a wildcard certificate and a single certificate for my domain structure which is:

app.example.com => single
*.app.example.com => wildcard

Both these routes should point to the same project directory on same server

Note: RapidSSL Support said that I had to purchase two as unlike classic domains example.com, my one is app.example.com, so that wildcard won't care my 3 decimal root

Now, I need to setup in nginx two different certificates. My default one (which works for my wildcard), however not 'app.example.com' as its ssl certificate is not included.

server {
    listen 443 ssl default_server;
    listen [::]:443 ssl default_server;

    ssl on;
    ssl_certificate /etc/ssl/ssl_certificate.cer;  // this is my wildcard cert
    ssl_certificate_key /etc/ssl/private.key;


    root /var/www/example/public;
    index index.php index.html index.htm;

    server_name .app.example.com;

    location / {
            try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
    }
 }

 // And for redirect:
server {
    listen 80 default_server;
    listen [::]:80 default_server;

    server_name .app.example.com;
    return 301 https://$server_name$request_uri;
}

How can I divide this into two and include my new certificate for app.example.com and keep wildcard as this?

已采纳解答

原帖链接 · Richard Smith · CC BY-SA 3.0

Use two server blocks, one for the single domain and one for the wildcard domain. Specify the appropriate server_name and ssl_certificate directives.

server {
    listen 443 ssl;
    listen [::]:443 ssl;

    server_name *.app.example.com;    
    ssl_certificate /etc/ssl/ssl_certificate1.cer;
    ssl_certificate_key /etc/ssl/private1.key;

    ...
}
server {
    listen 443 ssl;
    listen [::]:443 ssl;

    server_name app.example.com;    
    ssl_certificate /etc/ssl/ssl_certificate2.cer;
    ssl_certificate_key /etc/ssl/private2.key;

    ...
}

See this document for details.

You can use an include directive to pull common configuration into each block from some other file.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-12-07)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。