對不住了大家,最近在整小程序,一直沒時間寫點什麼。
今天寫的服務器配置方面的心得:一臺服務器配置多個域名證書。
這裡的域名證書是指免費申請到的域名證書,泛域名證書啥的就不在這說了。
默認情況下,咱們拿到的免費證書在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;
sendfile 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>
#
#location ~ \\.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP>
#
#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 Apache's document root
# concurs with nginx's 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格式是這樣的
配置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
}
}
到這裡,多域名配置就完畢了。
閱讀更多 ASP開發者 的文章