NGINX中虚拟主机上的SSL

NGINX中虚拟主机上的SSL,ssl,nginx,Ssl,Nginx,我是NGINX新手,我有一个案例,我需要用两个url调用一个网站,一个运行在HTTP上,另一个运行在HTTPS上。为了测试这一点,我已经在端口8080上创建了一个通过NGINX访问的虚拟站点,以及两个虚拟主机www.mytest1.local.com和www.mytest2.local.com,我需要只通过https协议访问www.mytest1.local.com,只通过http协议访问www.mytest2.local.com。以下是nginx.conf文件的快照:- http{ se

我是NGINX新手,我有一个案例,我需要用两个url调用一个网站,一个运行在HTTP上,另一个运行在HTTPS上。为了测试这一点,我已经在端口8080上创建了一个通过NGINX访问的虚拟站点,以及两个虚拟主机www.mytest1.local.com和www.mytest2.local.com,我需要只通过https协议访问www.mytest1.local.com,只通过http协议访问www.mytest2.local.com。以下是nginx.conf文件的快照:-

http{
   server {
     listen 443;
     server_name www.mytest1.local.com;
     ssl on;
     ssl_certificate C:\\Users\\sinhasu\\Downloads\\nginx-1.8.0\\SSL\\server.crt;
    ssl_certificate_key C:\\Users\\sinhasu\\Downloads\\nginx-1.8.0\\SSL\\server.key;
    location / {
    proxy_pass http://localhost:8080;
  }
 }

 server {
server_name www.mytest2.local.com;
location / {
    proxy_pass http://localhost:8080;
 }
}

server {
 listen 8080;
     location / {
    root C:\\Users\\sinhasu\\Downloads\\nginx-1.8.0\\testdoc;
 }
 }
}

但这种配置似乎运行不正常,这两个虚拟主机
www.mytest1.local.com
www.mytest2.local.com
都在
http
以及
https
协议上响应,而我希望mytest1url只接受
https
,mytest2url只接受
http协议


如果我在配置部分遗漏了什么,请告诉我。

这正是您想要的,您也能够在8080上访问http是nginx的默认行为。第二台服务器没有listen,因此它默认为端口80,甚至可能默认为443,而不指定listen指令