如何配置Nginx,实现http访问重定向到https?
现在越来越多的网站,当我们输入域名时,会自动重定向到https,我们只需要简单修改下Nginx配置文件/usr/local/nginx/conf/nginx.conf(根据个人的实际存储路径)即可。
1.添加443监听端口server
server {
listen 443 ssl;
server_name localhost www.***.com;#域名,如果有多个,可以用空格隔开
ssl_certificate ***.crt;#证书文件,路径相对于/usr/local/nginx/conf目录,也可以直接使用绝对路径
ssl_certificate_key ***.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 / {
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8000/;
}
}
2.然后添加80端口监听server,然后可利用以下两种方式进行重定向:
方式1:利用rewrite
server {
listen 80;
server_name localhost www.***.com;
rewrite ^(.*)$ https://$host$1 permanent;
}方式2:利用return 301
server {
listen 80;
server_name localhost www.xxx.com;
return 301 https://127.0.0.1$request_uri;
}
接下来通过浏览器访问服务器时,都是以https方式进行访问
如何配置Nginx,实现http访问重定向到https?的更多相关文章
- Nginx下HTTP强制重定向至HTTPS
Nginx下HTTP强制重定向至HTTPS 对于nginx来说,配置http强制重定向至https有多种多样的写法.可以直接rewrite,也可以用301重定向.但是直接拷贝网上的配置往往会出现问题, ...
- FastDFS 配置 Nginx 模块及访问测试
#备注:以下nginx-1.10.3源码目录根据nginx版本号不同会有相应的变化,以nginx版本号为准#一.安装 Nginx 和 fastdfs-nginx-module1,安装 Nginx 请看 ...
- nginx: 应用访问默认采用https
主要配置如下: #静态文件的访问 server { listen 443 ssl; server_name static.jksfrz.com; ssl_certificate d:/app/ngin ...
- (转)windows 下安装配置 Nginx 详解
windows 下安装配置 Nginx 详解 本文转自https://blog.csdn.net/kingscoming/article/details/79042874 nginx功能之一可以启动一 ...
- SpringBoot配置HTTPS,并实现HTTP访问自动转HTTPS访问
[转]https://www.jianshu.com/p/8d4aba3b972d 推荐使用nginx配置https,因本文产生的任何问题不再做回复. 这里说一下为什么写这篇文章,因为我也是一个Spr ...
- Nginx配置同一个域名同时支持http与https两种方式访问
Nginx配置同一个域名http与https两种方式都可访问,证书是阿里云上免费申请的 server{listen 80;listen 443 ssl;ssl on;server_name 域名;in ...
- Nginx安装配置|Nginx反向代理|Nginx支持HTTPS|Nginx重定向
Nginx安装配置 可以直接看到最下面的HTTPS. Nginx安装 我的系统如下: No LSB modules are available. Distributor ID: Ubuntu Desc ...
- [亲测]ASP.NET Core 2.0怎么发布/部署到Ubuntu Linux服务器并配置Nginx反向代理实现域名访问
前言 ASP.NET Core 2.0 怎么发布到Ubuntu服务器?又如何在服务器上配置使用ASP.NET Core网站绑定到指定的域名,让外网用户可以访问呢? 步骤 第1步:准备工作 一台Liun ...
- 为了解决linux配置Nginx 只能关闭防火墙才能访问的问题
使用Nginx和iptables做访问权限控制(IP和MAC) 之前配置的服务器,相当于对整个内网都是公开的,而且,除了可以通过80端口的nginx来间接访问各项服务,也可以绕过nginx,直 ...
随机推荐
- Dell Display Manager for Mac
Dell Display Manager for Mac DDM for macOS solution https://www.dell.com/community/Monitors/DDM-for- ...
- HTML a Tag All In One
HTML a Tag All In One HTML <a> target https://developer.mozilla.org/en-US/docs/Web/HTML/Elemen ...
- Javascript 严格模式("use strict";)详细解解
1 1 1 Javascript 严格模式("use strict";)详细解解 "use strict";定义JavaScript代码应该在"str ...
- how to using js to realize notes feature on the website
how to using js to realize notes feature on the website js & notes demos https://medium.com/brow ...
- Markdown & Static Site Generator
Markdown & Static Site Generator https://www.gitbook.com/ https://vuepress.vuejs.org/ https://ww ...
- flutter & dart & vs code & bug
flutter & dart & vs code & bug Waiting for another flutter command to release the startu ...
- React & Calendar
React & Calendar 日历 https://github.com/YutHelloWorld/calendar/blob/master/src/Calendar.js // 国际化 ...
- map & scale bug
map & scale TW bug https://antv.alipay.com/zh-cn/g2/3.x/demo/map/drill-down.html import React, { ...
- how to overwrite css !important style
how to overwrite css !important style css !important bug how to override css !important style https: ...
- window下象MAC一样工作的工具
前面是MAC 后面是windows对应工具,只是做一个列表说明,具体使用自行百度 1.item2 vs Cmder 命令行 2.Homebrew vs Chocolatey 包管理器 3.Spotli ...