腾讯云 Nginx 服务器 SSL 证书安装部署(Windows)

和其他服务器基本没啥差别

官方说明:

1、本文以证书名称 cloud.tencent.com 为例。

2、Nginx 版本以 nginx/1.24.0 为例。

3、当前服务器的操作系统为 Windows Server 2022,由于操作系统的版本不同,详细操作步骤略有区别。

4、安装 SSL 证书前,请您在服务器上开启 HTTPS 默认端口 443,避免证书安装后无法启用 HTTPS。

这简直是废话。

第一步。好了,先安装nginx吧。

去这里下载nginx:https://nginx.org/

如图:

最上面的一般书最新版本。点开。如图:

最上面的一般是最新版本。这里因为是windows环境,这里现在后面带windows的。下载下来的是zip压缩包。解压。如图:

如图,把ssl的证书解压之后,放在nginx的目录下。需要注意的是,ssl有针对不同容器的版本,这个在证书的管理页面下载时就可以看见,我这里用nginx来发布的,所以这里就需要nginx的版本。

第二步,打开nginx的nginx.conf配置文件,先备份一个原版的,然后修改成下面的

#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 index80.htm; //这个文件是我自己添加的,代替ngxin的默认页面,防止信息泄露。

}

#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 {

#SSL 默认访问端口号为 443

listen 443 ssl;

#请填写绑定证书的域名

server_name xxxxx.online;

#请填写证书文件的相对路径或绝对路径

ssl_certificate xxxxx.online_bundle.crt;

#请填写私钥文件的相对路径或绝对路径

ssl_certificate_key xxxxx.online.key;

ssl_session_timeout 5m;

#请按照以下协议配置

ssl_protocols TLSv1.2 TLSv1.3;

#请按照以下套件配置,配置加密套件,写法遵循 openssl 标准。

ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;

ssl_prefer_server_ciphers on;

#location / {

#网站主页路径。此路径仅供参考,具体请您按照实际目录操作。

#例如,您的网站主页在 Nginx 服务器的 /etc/www 目录下,则请修改 root 后面的 html 为 /etc/www。

root html;

index index80.htm;

#}

location /api/{

proxy_set_header Host $http_host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header REMOTE-HOST $remote_addr;

add_header 'Access-Control-Allow-Credentials' 'true';

add_header 'Access-Control-Allow-Origin' '*';

add_header 'Access-Control-Allow-Methods' 'GET,POST,PATCH,OPTIONS';

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_pass http://localhost:15666/; //这个是本地应用http正常发布的地址。记得在防火墙里面需要把相应的端口、80端口、443端口全部开放。否则nginx代理转跳的时候跳不过去。

}

}

}

第三步,启动nginx。这样就好了。试试外面用https访问你的域名。当然还要记得域名要备案,否则访问还是不通的,或者通了几天就被封了。

相关推荐
189228048614 分钟前
NY270NY273美光固态闪存NY277NY287
服务器·网络·数据库·科技·性能优化
你好,赵志伟1 小时前
Socket 编程 TCP
linux·服务器·tcp/ip
Liang_GaRy2 小时前
心路历程-三个了解敲开linux的大门
linux·运维·服务器
玩转以太网10 小时前
基于W55MH32Q-EVB 实现 HTTP 服务器配置 OLED 滚动显示信息
服务器·网络协议·http
小晶晶京京11 小时前
day34-LNMP详解
linux·运维·服务器
画个太阳作晴天11 小时前
A12预装app
linux·服务器·前端
碎像12 小时前
Linux上配置环境变量
linux·运维·服务器
sunflower_w13 小时前
linux I2C核心、总线与设备驱动
linux·运维·服务器
Ronin30514 小时前
【Linux系统】进程间通信:System V IPC——共享内存
linux·服务器·system v 共享内存
伊成15 小时前
Docker 部署 Nginx 完整指南
nginx·docker·容器