Linux服务之nginx服务篇四(配置https协议访问)
一、配置nginx支持https协议访问
编译安装nginx的时候需要添加相应的模块--with-http_ssl_module和--with-http_gzip_static_module(可通过/usr/local/nginx/sbin/nginx -V来查看nginx编译参数)
(yum安装不需要)
二、防火墙开启https协议默认端口443
1、vi /etc/sysconfig/iptables #编辑防火墙配置文件,添加以下代码:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
:wq! #保存退出
service iptables restart #重启防火墙
2、或者使用firewall-cmd添加防火墙规则
firewall-cmd --add-port=443/tcp
firewall-cmd --add-port=443/tcp --permanent
三、创建https证书
确保机器上安装了OpenSSL和openssl-devel
yum install openssl openssl-devel #CentOS使用yum命令安装
mkdir /etc/nginx/ssl #创建证书存放目录
cd /etc/nginx/ssl #进入目录 创建服务器私钥:
openssl genrsa -des3 -out server.key 1024 #根据提示输入证书口令(ryz123) 创建签名请求的证书(CSR):
openssl req -new -key server.key -out server.csr #输入上面设置的口令(ryz123)
#根据提示输入相应的信息
Country Name (2 letter code) [XX]:cn #国家
State or Province Name (full name) []:shanxi #省份
Locality Name (eg, city) [Default City]:taiyuan #城市
Organization Name (eg, company) [Default Company Ltd]:3344 #公司
Organizational Unit Name (eg, section) []:yunwei #部门
Common Name (eg, your name or your server's hostname) []:3344 #主机名称
Email Address []:[email protected] #邮箱
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:123456 #证书请求密钥,CA读取证书的时候需要输入密码
An optional company name []:3344 #公司名称,CA读取证书的时候需要输入密码 openssl rsa -in server.key -out server_nopassword.key #对key进行解密
openssl x509 -req -days 365 -in server.csr -signkey server_nopassword.key -out server.crt #标记证书使用上述私钥(ryz123)和CSR [root@s2 ssl]# ls
server.crt server.csr server.key server_nopassword.key
[root@s2 ssl]# pwd
/etc/nginx/ssl
四、修改nginx的配置文件,网站添加安全验证(https)
server {
listen 80;
server_name www.3344.com;
location / {
rewrite ^(.*)$ https://$host$1 permanent; #把http协议重定向到https上面
}
}
server {
listen 443 ssl;
server_name www.3344.com;
ssl_certificate "/etc/nginx/ssl/server.crt";
ssl_certificate_key "/etc/nginx/ssl/server_nopassword.key";
fastcgi_param HTTPS $https if_not_empty; #有https协议时自动使用https,否则忽略这个参数。
root /var/www/html;
}
Linux下nginx配置https协议访问如上。
Linux服务之nginx服务篇四(配置https协议访问)的更多相关文章
- 【转】Linux下nginx配置https协议访问的方法
一.配置nginx支持https协议访问,需要在编译安装nginx的时候添加相应的模块--with-http_ssl_module 查看nginx编译参数:/usr/local/nginx/sbin/ ...
- Tomcat配置https协议访问
Tomcat9配置https协议访问: https://blog.csdn.net/weixin_42273374/article/details/81010203 配置Tomcat使用https协议 ...
- Linux下nginx配置https协议访问
一.配置nginx支持https协议访问,需要在编译安装nginx的时候添加相应的模块--with-http_ssl_module 查看nginx编译参数:/usr/local/nginx/sbin/ ...
- Linux下nginx配置https协议访问的方法
一.配置nginx支持https协议访问,需要在编译安装nginx的时候添加相应的模块--with-http_ssl_module 查看nginx编译参数:/usr/local/nginx/sbin/ ...
- nginx反向代理批量实现https协议访问
我们进入大多数HTTPS网站ie浏览器都会给出相关提醒了,但我配置了一台HTTPS代理机器发现css与js都加载不了,这个有朋友说是https页面,如果加载http协议的内容,会被认为页面不安全,所以 ...
- 【netcore基础】CentOS 7.6.1810 搭建.net core 2.1 linux 运行环境 nginx反向代理 supervisor配置自启动
之前写过一篇Ubuntu的环境搭建博客,感觉一些配置大同小异,这里重点记录下 nginx 作为静态 angular 项目文件服务器的配置 参考链接 [netcore基础]ubuntu 16.04 搭建 ...
- 在linux下的apache配置https协议,开启ssl连接
环境:linux 配置https协议,需要2大步骤: 一.生成服务器证书 1.安装openssl软件 yum install -y openssl mod_ssl 2.生成服务器私匙,生成server ...
- 使用nginx代理后以及配置https后,如何获取真实的ip地址
使用nginx代理后以及配置https后,如何获取真实的ip地址 Date:2018-8-27 14:15:51 使用nginx, apache等反向代理后,如果想获取请求的真实ip,要在nginx中 ...
- nginx证书制作以及配置https并设置访问http自动跳转https(反向代理转发jboss)
nginx证书制作以及配置https并设置访问http自动跳转https 默认情况下ssl模块并未被安装,如果要使用该模块则需要在编译时指定–with-http_ssl_module参数,安装模块依赖 ...
随机推荐
- OO第四单元&课程总结
一.本单元架构设计 第一次作业 本次作业要求解析UML类图. 首先,将UML中的各个元素(比如UmlClass.UmlInterface等)转化成自己定义的类(MyClass.MyInterface) ...
- Java中获取类的运行时结构
获取运行时类的完整结构 通过反射获取运行时类的完整结构 Field(属性).Method(方法).Constructor(构造器).Superclass(父类).Interface(接口).Annot ...
- 1.PreparedStatement VS Statement
两者都是Sun公司定义的接口,PreparedStatement属于Statement的子接口.二者类似信使,向数据库中执行sql语句: Statement存在拼串的操作,比较繁琐:存在SQL注入问题 ...
- 让你的Windows/Linux玩上Switch!
1 前言 某天在Github上面看到了两个Switch的模拟器: yuzu Ryujinx 于是就想动手想尝试一下在Linux上面玩上Switch. 本文首先简单介绍一下两个模拟器,接着是两个模拟器的 ...
- String a=new String("abc")创建了几个对象
String str=new String("abc"); 紧接着这段代码之后的往往是这个问题,那就是这行代码究竟创建了几个String对象呢? 相信大家对这道题并不陌生,答案 ...
- TCP:与UDP区别、三次握手、四次挥手、Socket 编程
1. TCP 基本认识 TCP 头部格式 为什么需要 TCP 协议?TCP 工作在哪一层? 什么是 TCP ? 什么是 TCP 连接? 如何唯一确定一个 TCP 连接呢? 有一个 IP 的服务器监听了 ...
- istio1.2.2 安装及使用示例
前言 本文介绍istio的安装及使用 dashboard,grafana,prometheus,kiali,jaeger的配置示例.演示通过istio的ingressgateway统一访问入口 Ist ...
- Python容器相关操作
(集合与字典除外)的容器相关操作 (1)容器的拼接 >>> 'abc' + 'def' 'abcdef' (2)容器的重复 >>> (1, 2) * 3 (1, 2 ...
- Python 3.10 中新的功能和变化
随着最后一个alpha版发布,Python 3.10 的功能更改全面敲定! 现在,正是体验Python 3.10 新功能的理想时间!正如标题所言,本文将给大家分享Python 3.10中所有重要的功能 ...
- 【Set】Set集合求并集,交集,差集
/** * @author: Sam.yang * @date: 2020/11/16 11:14 * @desc: Set集合操作工具类 */ public class SetOptUtils { ...