一、配置nginx支持https协议访问,需要在编译安装nginx的时候添加相应的模块--with-http_ssl_module
查看nginx编译参数:/usr/local/nginx/sbin/nginx -V
如下所示:
configure arguments: --prefix=/usr/local/nginx --with-google_perftools_module --without-http_memcached_module --user=www --group=www --with-http_stub_status_module --with-http_sub_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=/usr/local/src/openssl-1.0.1h --with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.35
如果没有--with-http_gzip_static_module这个参数,需要重新编辑nginx
二、防火墙开启https协议默认端口443
vi /etc/sysconfig/iptables #编辑防火墙配置文件,添加以下代码
-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
:wq! #保存退出
service iptables restart #重启防火墙
三、创建https证书
确保机器上安装了openssl和openssl-devel
yum install openssl openssl-devel #CentOS使用yum命令安装
mkdir /usr/local/nginx/conf/ssl #创建证书存放目录
cd /usr/local/nginx/conf/ssl #进入目录
创建服务器私钥:openssl genrsa -des3 -out server.key 1024 #根据提示输入证书口令
创建签名请求的证书(CSR):openssl req -new -key server.key -out server.csr #输入上面设置的口令
#根据提示输入相应的信息
Country Name (2 letter code) [XX]:cn #国家
State or Province Name (full name) []:zhejiang #省份
Locality Name (eg, city) [Default City]:hangzhou #城市
Organization Name (eg, company) [Default Company Ltd]:osyunwei #公司
Organizational Unit Name (eg, section) []:sys #部门
Common Name (eg, your name or your server's hostname) []:osyunwei #主机名称
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 []:osyunwei #公司名称,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
#标记证书使用上述私钥和CSR
四、修改nginx配置文件,加载ssl证书
vi /usr/local/nginx/conf/nginx.conf #编辑
listen 80;
listen 443;
ssl on;
ssl_certificate /usr/local/nginx/conf/ssl/server.crt;
ssl_certificate_key /usr/local/nginx/conf/ssl/server_nopassword.key;
fastcgi_param HTTPS $https if_not_empty; #有https协议时自动使用https,否则忽略这个参数。
:wq! #保存退出
service nginx restart #重启nginx
rewrite ^(.*) https://www.osyunwei.com$1 permanent; #可以把http协议重定向到https上面
使用https协议打开网址,如下图所示:
至此,Linux下nginx配置https协议访问完成。
nginx,https协议
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
更新日志
- 魏新雨《为你祈祷+新歌精逊2CD[WAV]
- 影心、明萨拉你选哪个?国外美女COS《博德3》
- 澳洲女子骑车跌入“自杀树”丛 疼痛持续9个月崩溃
- 育碧公布2024“她创力”计划:为女性游戏人提供辅导
- 刘美君.2017-千色·30总选3CD【环球】【WAV+CUE】
- 群星.2022-星河长明电视原声带【乐有奇思】【FLAC分轨】
- 陈淑桦.1995-淑桦盛开Forever【滚石】【WAV+CUE】
- 《再来一张》评测:出师成败皆系“赌”
- 《银河汉堡店》测评:我是银河走菜王!
- 《末日地带2》评测:酣畅淋漓的“和面”之旅
- 萧煌奇《没事的》[320K/MP3][96.22MB]
- 萧煌奇《没事的》[FLAC/分轨][263.38MB]
- 群星《音你而来 第6期》[320K/MP3][90.61MB]
- 交错战线爬塔攻略一览
- 战锤40K星际战士2全近战武器使用教学|近战武器连招表