第一步是要进行IIS配置
前提需要对SSL名称做备注,具体点击这里
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,进入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