热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

一天一点linux(19):配置https

Nginx配置https#腾讯云证书文档https:cloud.tencent.comdocumentproduct4004143备注,手动编译安装需要安加入SSL模块(http_

Nginx配置https

#腾讯云证书文档
https://cloud.tencent.com/document/product/400/4143

备注,手动编译安装需要安加入 SSL 模块(http_ssl_module)

示例

server {
# 开启https端口
listen 443 ssl;
# 填写绑定证书的域名
server_name xxx.com;
# nginx的错误日志
access_log /var/log/nginx/sd-access.log;
error_log /var/log/nginx/sd-error.log;
# 默认网站根目录
root /data/releases/websites/sd/htdocs;
# 将以下路由下放到前台
location ~ (^/taskm)|(^/perm)|(^/data) {
try_files $uri /index.html;
}
location / {
# 入口文件,注意这里有先后顺序
index index.html index.php index.htm;
if (!-e $request_filename) {
rewrite . /index.php last;
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# https证书配置
# 开启ssl
ssl on;
# 证书文件
ssl_certificate /usr/local/nginx/conf/ssl/xxxx.crt;
# 私钥文件
ssl_certificate_key /usr/local/nginx/conf/ssl/xxxx.key;
# 配置会话超时时间
ssl_session_timeout 5m;
# 配置共享会话缓存大小
ssl_session_cache shared:SSL:10m;
# ssl_protocols 和 ssl_ciphers 用来限制连接只包含 SSL/TLS 的加強版本和算法
# 配置协议
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
# 配置加密套件
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
# 优先采取服务器算法
ssl_prefer_server_ciphers on;
# Fastcgi服务器和程序(PHP,Python)沟通的协议.
location ~ \.php$ {
# 设置监听端口
fastcgi_pass 127.0.0.1:9000;
# 设置nginx的默认首页文件,上面index设置过
fastcgi_index index.php;
# 设置脚本文件请求的路径
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# 引入fastcgi的配置文件
include fastcgi_params;
fastcgi_param SERVER_NAME $http_host;
fastcgi_ignore_client_abort on;
fastcgi_connect_timeout 600s;
fastcgi_send_timeout 600s;
fastcgi_read_timeout 600s;
}
# 对图片缓存时间设置
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
expires 30d;
access_log off;
}
# 对JS和CSS缓存时间设置
location ~ .*\.(js|css)?$ {
expires 7d;
access_log off;
}
}
# 使用全站加密,HTTP 自动跳转 HTTPS, 注意配置这里上面就不能再监听80端口
server {
# 80端口访问
listen 80;
# 配置访问域名 不包含协议
server_name xxx.com;
# 使用url重写模块重写url 访问非https的url重定向到http上去
rewrite ^/(.*) https://$host/$1 permanent;
}

推荐阅读
author-avatar
camera98
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有