使用nginx的301状态码

server {
listen ;
    if ($scheme = 'http') {
    return 301 https://$server_name$request_uri;
    }
# 下面是一种旧的写法
# if ( $scheme = 'http' ){rewrite ^(.*)$  https://$host$1 permanent;}
    listen  ssl http2;
server_name xxx.com;
ssl_certificate /usr/local/nginx/ssl/xxx.com.crt;
ssl_certificate_key /usr/local/nginx/ssl/xxx.com.key;
ssl_trusted_certificate /usr/local/nginx/ssl/xxx.com.crt; # SSL
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off; # Mozilla Intermediate configuration
ssl_protocols TLSv1. TLSv1.;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384; # OCSP Stapling
ssl_stapling on;
ssl_stapling_verify on;
resolver 1.1.1.1 1.0.0.1 8.8.8.8 8.8.4.4 208.67.222.222 208.67.220.220 valid=60s;
resolver_timeout 2s; # reverse proxy
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_cache_bypass $http_upgrade; proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
} # favicon.ico
location = /favicon.ico {
log_not_found off;
access_log off;
} # robots.txt
location = /robots.txt {
log_not_found off;
access_log off;
} # assets, media
location ~* \.(?:css(\.map)?|js(\.map)?|jpe?g|png|gif|ico|cur|heic|webp|tiff?|mp3|m4a|aac|ogg|midi?|wav|mp4|mov|webm|mpe?g|avi|ogv|flv|wmv)$ {
expires 7d;
access_log off;
} # svg, fonts
location ~* \.(?:svgz?|ttf|ttc|otf|eot|woff2?)$ {
add_header Access-Control-Allow-Origin "*";
expires 7d;
access_log off;
} # gzip
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level ;
gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml; }

nginx 配置 强制访问https的更多相关文章

  1. Windows下Nginx配置SSL实现Https访问(包含证书生成)

    Vincent.李   Windows下Nginx配置SSL实现Https访问(包含证书生成) Windows下Nginx配置SSL实现Https访问(包含证书生成) 首先要说明为什么要实现https ...

  2. Centos7.2下Nginx配置SSL支持https访问(站点是基于.Net Core2.0开发的WebApi)

    准备工作 1.基于nginx部署好的站点(本文站点是基于.Net Core2.0开发的WebApi,有兴趣的同学可以跳http://www.cnblogs.com/GreedyL/p/7422796. ...

  3. nginx 配置多个 https 域名访问

    需要此操作的原因 在服务器上部署了 halo blog 以后,这次需要部署另外一个项目,但是又不想使用 ip + port,因此选择使用 nginx 配置多个域名访问. nginx 配置 server ...

  4. nginx配置自签名https

    nginx配置https是需要CA颁发证书的,为了测试方便,我们可以使用自签名证书 1.如何生成自签名证书 1.1:我们需要为服务端和客户端准备私钥和公钥: //生成服务器端私钥 openssl ge ...

  5. Nginx. 用http访问https跨域

    用http 访问 https域名, 报跨越问题 解决方法: 在nginx相应服务的转发配置下添加: add_header 'Access-Control-Allow-Origin' 'http://i ...

  6. 使用SSL安全证书和nginx配置将域名HTTPS化

    一.在阿里云后台申请免费版证书: 二.在域名解析里面添加记录: 三.提交审核: 四.等待审核通过后,下载nginx证书: 五.按照文档修改nginx配置文件: https://help.aliyun. ...

  7. linux下nginx配置ssl证书(https)

    nginx配置ssl很简单,首先需要两个文件,一个是crt文件,另一个是key文件,如下所示: xxx.crt;  #(证书公钥)xxx.key; #(证书私钥) 把这两个文件放到nginx的conf ...

  8. nginx配置目录访问&用户名密码控制

    背景 项目上需要一些共享目录让外地同事可以网页访问对应的文件,且受权限控制: 现有环境: centos nginx 你可以了解到以下内容: 配置nginx开启目录访问 并配置nginx用户名和密码进行 ...

  9. nginx配置http访问自动跳转到https

    1.按照如下格式修改nginx.conf 配置文件,80端口会自动转给443端口,这样就强制使用SSL证书加密了.访问http的时候会自动跳转到https上面 server { listen ; se ...

随机推荐

  1. php 关于php创建 json文件 和 对文件增删改查 示例

    <?php //fopen($file,'w'); //打开文件/创建文件 //file_put_contents($file,$content)//写入文件 //file_get_conten ...

  2. iptables 实例

    开启ip段192.168.1.0/24端的80口 开启ip段211.123.16.123/24端ip段的80口 # iptables -I INPUT -p tcp --dport 80 -j DRO ...

  3. iptables服务器主机防火墙

    iptables参数说明: Commands: Either long or short options are allowed. --append -A chain 链尾部追加一条规则 --dele ...

  4. implements Serializable有什么作用?

    没有implements Serializable,你就不能通过rmi(包括ejb)提供远程调用.serialization 允许你将实现了Serializable接口的对象转换为字节序列,这些字节序 ...

  5. Python3标准库:copy复制对象

    1. copy复制对象 copy模块包括两个函数copy()和deepcopy(),用于复制现有的对象. 1.1 浅副本 copy()创建的浅副本(shallow copy)是一个新容器,其中填充了原 ...

  6. springboot 后台框架平台 mybatis 集成代码生成器 shiro 权限 websocket

    1.代码生成器: [正反双向](单表.主表.明细表.树形表,快速开发利器)freemaker模版技术 ,0个代码不用写,生成完整的一个模块,带页面.建表sql脚本.处理类.service等完整模块2. ...

  7. rpm 程序包管理介绍

    API:application program interface ABI:application binary interface linux系统的ABI文件是ELF格式的 windows系统的AB ...

  8. markdown语法链接新页面打开

    我们在写markdown语法的文章时,经常会写超链接,默认markdown的写法超链接打开页面都是在当前页面,对自己页面的访问不是很好,所以我们一般都希望在新页面打开.但是据我对markdwon的语法 ...

  9. JS淘宝浏览商品

    <!DOCTYPE html> <html lang="en"> <head>     <meta charset="UTF-8 ...

  10. CF547E Mike and Friends [AC自动机,离线树状数组]

    #include <cstdio> #include <queue> #include <vector> #define pb emplace_back using ...