一台服务器IIS配置多个域名证书

运维

  对不住了大家,最近在整小程序,一直没时间写点什么。

  今天写的服务器配置方面的心得:一台服务器配置多个域名证书。

  这里的域名证书是指免费申请到的域名证书,泛域名证书啥的就不在这说了。

  默认情况下,咱们拿到的免费证书在IIS中只能在一个域名中使用,如果想多个域名都使用证书的话,就需要NGINX配合。

  具体步骤如下:

  1.在NGINX官网下载最新的稳定版。

  2.解压到服务器,并打开NGINX目录中conf文件夹下的nginx.cnf文件。

  3.会看到类似如下内容:

  #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;

   sfile on;

   #tcp_nopush on;

   #keepalive_timeout 0;

   keepalive_timeout 65;

   #gzip on;

   server {

   listen 80;

   server_name localhost;

   #charset koi8-r;

   #access_log logs/host.access.log main;

   location / {

   root html;

   index index.html index.htm;

   }

   #error_page 404 /404.html;

   # redirect server error pages to the static page /50x.html

   #

   error_page 500 502 503 504 /50x.html;

   location = /50x.html {

   root html;

   }

   # proxy the PHP scripts to Apache listening on 127.0.0.1:80

   #

   #location ~ \.php$ {

   # proxy_pass http://127.0.0.1;

   #}

   # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

   #

   #location ~ \.php$ {

   # root html;

   # fastcgi_pass 127.0.0.1:9000;

   # fastcgi_index index.php;

   # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

   # include fastcgi_params;

   #}

   # deny access to .htaccess files, if Apaches document root

   # concurs with nginxs one

   #

   #location ~ /\.ht {

   # deny all;

   #}

   }

   # 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 localhost;

   # ssl_certificate cert.pem;

   # ssl_certificate_key cert.key;

   # ssl_session_cache shared:SSL:1m;

   # ssl_session_timeout 5m;

   # ssl_ciphers HIGH:!aNULL:!MD5;

   # ssl_prefer_server_ciphers on;

   # location / {

   # root html;

   # index index.html index.htm;

   # }

   #}

  }

  咱们主要的是http{}里的内容

  配置http格式是这样的

http配置

  配置https格式是这样的

https配置

  在http{}中,每一个server{}都是一个http服务。按照上面的格式复制多个。就可以完成配置。

  4.停止IIS,将所有网站的绑定http端口修改成非80的任意端口,我这里改的是88端口。https端口每个都不能相同。比如从444开始,每增加一个https站点,端口就加一445,446.....

  6.都修改完毕后,启动NGINX,如果配置没错的话,正常情况,你的网站就可以正常访问了。

  最后,着重说一下https的配置。

  server{

   listen 443;#htts默认端口号。

   server_name xxx.xxx #你的域名写在这里。

  ssl on;

   ssl_certificate 你证书的pem文件位置

   ssl_certificate_key 你证书的key文件位置

   ssl_session_timeout5m;

  ssl_protocols TLSv1TLSv1.1 TLSv1.2;

  ssl_ciphersECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;

  ssl_prefer_server_ciphers on;

  ssl_session_cacheshared:SSL:1m;

   location / {

   proxy_pass 你的https网址+端口号 即https://xxx.xxx:444

   }

  }

  到这里,多域名配置就完毕了。

标签: 运维