nginx解决IIS7.5只能使用一个SSL的问题


前提需要对SSL名称做备注,具体点击这里

IIS配置如图所示

这个是IIS配置图
特别要注意的是,选择类型为:https,SSL证书也要正确选择。
另外,不同的站点要使用不同的端口。

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  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 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;
#    }
#}
server {  
    listen 443 ssl;
    server_name  域名1;  
    #ssl             on;
    ssl_certificate "SSL证书路径";    
    ssl_certificate_key  "SSL证书密钥";  
    ssl_session_cache    shared:SSL:1m;
    ssl_session_timeout  5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 
    ssl_ciphers ECDH:AESGCM:HIGH:!RC4:!DH:!MD5:!3DES:!aNULL:!eNULL;
    ssl_prefer_server_ciphers  on;

	location / {  
    proxy_pass https://localhost:807/;
    proxy_set_header   Host    $host;  
    proxy_set_header   X-Real-IP   $remote_addr;  
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;  
	}
}
server {  
    listen 443 ssl;
    server_name  域名2;  
    #ssl             on;
    ssl_certificate      "SSL证书路径";    
    ssl_certificate_key  "SSL证书密钥";  
    ssl_session_cache    shared:SSL:1m;
    ssl_session_timeout  5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 
    ssl_ciphers ECDH:AESGCM:HIGH:!RC4:!DH:!MD5:!3DES:!aNULL:!eNULL;
    ssl_prefer_server_ciphers  on;

	location / {  
    proxy_pass https://localhost:808/;
    proxy_set_header   Host    $host;  
    proxy_set_header   X-Real-IP   $remote_addr;  
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;  
	}
}

}

会出现的问题

1. nginx: [emerg] bind() to 0.0.0.0:80 failed或错误信息是bind() to 0.0.0.0:80 failed (10013: An attempt was made to access a socket in a way forbidden by its access permissions)
出现上面的问题,是因为80端口被占用,而nginx监听不监听80端口是可以在nginx.conf中配置的。这里面特别要注意的一点就是,也许在 listen 80前面加了“#”号,即已经注解掉。但还是会有这个错误。这是因为只注释掉 listent 80 这块并不能解决问题。因为还必须要把listen 80上面的" server { "也要注释掉。这个非常重要。
注意:把80端口改为其他端口并不好使。

2.nginx本地正常访问,外网无法访问
这个问题是因为windows server 的防火墙没有进行nginx配置,必须允许nginx.exe通过防火墙。如下图:
nginx防火墙配置

Nginx的命令行

启动nginx,进入window的dos命令行编辑器,dos窗口建议用管理员权限运行。
E:\nginx-1.14.2>nginx.exe // 直接回车 or
E:\nginx-1.14.2>start nginx.exe // 回车

注意:第二种比第一种操作好,第一种会一直在命令行窗口执行,不能进行其他指令操作,需要在任务管理器中关闭进程。

修改ng配置之后需要重新启动ng
E:\nginx-1.14.2>nginx.exe -s reload // 重新启动

关闭nginx
E:\nginx-1.14.2> nginx.exe -s stop // or
E:\nginx-1.14.2> nginx.exe -s quit

注意:stop是快速停止nginx,可能并不保存相关信息;quit是完整有序的停止nginx,并保存相关信息。

查看nginx版本
E:\nginx-1.14.2> nginx.exe -v

查看nginx日志
E:\nginx-1.14.2> nginx.exe -s reopen

nginx.exe 其他错误

问题:
nginx重新启动出错nginx: [error] OpenEvent(“Global\ngx_reload_3968”) failed (5: Access is denied)
解决方法:
nginx: [error] OpenEvent(“Global\ngx_reload_3968”) failed (5: Access is denied)

权限不够:使用管理员启动
在这里插入图片描述
问题:
Nginx错误:nginx: [error] OpenEvent(“Global\ngx_reload_6252”) failed (2: The system cannot find the file specified)
解决方法:
执行nginx -s reload命令:

nginx: [error] OpenEvent(“Global\ngx_reload_6252”) failed (2: The system cannot find the file specified)

错误原因:

Nginx 尚未启动导致,执行 start nginx 命令开启Nginx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值