Nginx实现多域名证书HTTPS

实现一台服务器,两个域名。
首先需要两个域名,获取到CA证书,两个域名就得到两套证书,
然后配置nginx,如下:


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  127.0.0.1;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    server {
        listen       443 ssl;
        server_name  域名1;

        ssl_certificate      ssl/8757584_www.*****.pem;
        ssl_certificate_key  ssl/8757584_www.*****.key;


        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;		
    }
	
	server {
        listen       443 ssl;
        server_name  域名2;

		
		ssl_certificate      ssl/9547749_www.*****.pem;
        ssl_certificate_key  ssl/9547749_www.******.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;		
    }
}

效果:
Nginx实现多域名证书HTTPS_第1张图片

Nginx实现多域名证书HTTPS_第2张图片

你可能感兴趣的:(nginx,多域名)