Nginx SSL配置
16lz
2021-05-05
准备
服务器centos7,证书为阿里云Symantec 免费型DV SSL证书
Nginx已经安装
配置
将配置文件修改即可
如下,我的配置文件在/etc/nginx/vhost/test1.conf
修改配置很简单,将之前的80服务的配置改为443的端口,加上ssl配置即可
再添加一个80服务,将http转发到https即可
配置如下:
server { listen 80; server_name nginx1.shadowwu.club; rewrite ^(.*)$ https://$host$1 permanent;}server { listen 443; server_name nginx1.shadowwu.club; ssl on; root /usr/share/nginx/html/nginx1.shadowwu.club; index index.php index.html index.htm; ssl_certificate cert/214830400260231.pem; ssl_certificate_key cert/214830400260231.key; ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; location / { # WordPress固定链接URL重写 if (!-e $request_filename) { rewrite (.*) /index.php; } } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } # 这里新加的 # PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI协议默认配置. # Fastcgi服务器和程序(PHP,Python)沟通的协议. location ~ \.php$ { # 设置监听端口 fastcgi_pass 127.0.0.1:9000; # 设置nginx的默认首页文件(上面已经设置过了,可以删除) fastcgi_index index.php; # 设置脚本文件请求的路径 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # 引入fastcgi的配置文件 include fastcgi_params; }}
将其中的 server_name改为自己的域名
ssl_certificate cert/214830400260231.pem; ssl_certificate_key cert/214830400260231.key;
改为自己ssl证书的地址即可
我的证书上传在服务器的/etc/nginx/cert下
首先安装上传下载功能
yun install -y lrzsz
新建目录
mkdir /etc/nginx/certcd /etc/nginx/certrz
选中本地的证书上传即可
重启服务器
systemctl restart nginx
好知识,才能预见未来
赞赏
0人进行了赞赏支持
更多相关文章
- 最全面的SpringBoot配置文件详解
- 从零搭建Spring Boot脚手架(2):集成mybatis
- LNMP环境的搭建配置
- Sonarqube和Jenkins pipeline的使用
- Spring MVC项目基本配置
- 用 Keepalived+HAProxy 实现高可用负载均衡的配置方法
- SaltStack 工作原理及安装配置实例详解 | 运维进阶
- 双 VIOS 环境如何配置心跳网卡?
- Virtualbox的centos7 nat和桥接网络配置