一、网站部署到IIS 配置Nginx反向代理后,用户访问网站会首先到nginx服务,然后再由nginx转发到iis,所以这种情况80和443端口就要预留给nginx。在IIS部署网站时需要指定其他端口,同时也
server {
listen 80; #监听80端口,就是监听http访问
server_name www.test.com;
location / {
proxy_ssl_server_name on;
root html;
index index.html index.htm;
proxy_pass http://127.0.0.1:8080;#仅仅是代理跳转演示,没有跳转到https。 其中127.0.0.1:8080是在IIS绑定的网站端口
}
}
server {
listen 80; #监听80端口,就是监听http访问
server_name api.test.com;
location / {
proxy_ssl_server_name on;
root html;
index index.html index.htm;
rewrite ^(.*)$ https://${server_name}$1 permanent; #http://api.test.com自动跳转 https://api.test.com
}
}
server {
listen 443 http2 ssl;
server_name www.test.com;
ssl_certificate www.test.com.pem # 没有/开头路径是从nginx.conf所在的文件夹开始的,也就是conf
ssl_certificate_key /nginx/conf/www.test.com.key #/开头的路径是从nginx所在盘符开始算起的
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDH:AESGCM:HIGH:RSA+3DES:!RC4:!DH:!MD5:!aNULL:!eNULL;
ssl_prefer_server_ciphers on;
#access_log cert/test.log; #网站访问日志
location / {
proxy_ssl_server_name on;
root html;
index index.html index.htm;
proxy_pass http://127.0.0.1:8090; #8090 是在IIS配置的端口号 8080 已经给http请求了
}
}
server {
listen 443 http2 ssl;
server_name api.test.com;
ssl_certificate cert/api.test.com.pem; # 没有/开头路径是从nginx.conf所在的文件夹开始的 ,也就是conf
ssl_certificate_key cert/api.test.com.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDH:AESGCM:HIGH:RSA+3DES:!RC4:!DH:!MD5:!aNULL:!eNULL;
ssl_prefer_server_ciphers on;
#access_log cert/test.log;
#https正常反向代理
location / {
proxy_ssl_server_name on;
root html;
index index.html index.htm;
proxy_pass http://127.0.0.1:8088;
}
#访问wss://api.test.com/wss时,会匹配下面规则,自动转发到8099端口
location /wss {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade; #重要
proxy_set_header Connection "Upgrade"; #重要
proxy_pass http://127.0.0.1:8099;#好像是上面两个重要配置会把http://127.0.0.1:8099转发为或者iis会识别为ws://127.0.0.1:8099
}
}
发表评论