Linux下nginx配置https協(xié)議訪問(wèn)的方法
一、配置nginx支持https協(xié)議訪問(wèn),需要在編譯安裝nginx的時(shí)候添加相應(yīng)的模塊--with-http_ssl_module
查看nginx編譯參數(shù):/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
如果沒(méi)有--with-http_gzip_static_module這個(gè)參數(shù),需要重新編輯nginx
二、防火墻開啟https協(xié)議默認(rèn)端口443
vi /etc/sysconfig/iptables #編輯防火墻配置文件,添加以下代碼
-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
:wq! #保存退出
service iptables restart #重啟防火墻
三、創(chuàng)建https證書
確保機(jī)器上安裝了openssl和openssl-devel
yum install openssl openssl-devel #CentOS使用yum命令安裝
mkdir /usr/local/nginx/conf/ssl #創(chuàng)建證書存放目錄
cd /usr/local/nginx/conf/ssl #進(jìn)入目錄
創(chuàng)建服務(wù)器私鑰:openssl genrsa -des3 -out server.key 1024 #根據(jù)提示輸入證書口令
創(chuàng)建簽名請(qǐng)求的證書(CSR):openssl req -new -key server.key -out server.csr #輸入上面設(shè)置的口令
#根據(jù)提示輸入相應(yīng)的信息
Country Name (2 letter code) [XX]:cn #國(guó)家
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 #主機(jī)名稱
Email Address []:[email protected] #郵箱
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:123456 #證書請(qǐng)求密鑰,CA讀取證書的時(shí)候需要輸入密碼
An optional company name []:osyunwei #公司名稱,CA讀取證書的時(shí)候需要輸入密碼
openssl rsa -in server.key -out server_nopassword.key #對(duì)key進(jìn)行解密
openssl x509 -req -days 365 -in server.csr -signkey server_nopassword.key -out server.crt
#標(biāo)記證書使用上述私鑰和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協(xié)議時(shí)自動(dòng)使用https,否則忽略這個(gè)參數(shù)。
:wq! #保存退出
service nginx restart #重啟nginx
rewrite ^(.*) https://www.osyunwei.com$1 permanent; #可以把http協(xié)議重定向到https上面
使用https協(xié)議打開網(wǎng)址,如下圖所示:
至此,Linux下nginx配置https協(xié)議訪問(wèn)完成。
- Nexus使用nginx代理實(shí)現(xiàn)支持HTTPS協(xié)議
- Nginx接收Http協(xié)議請(qǐng)求轉(zhuǎn)發(fā)使用Https協(xié)議的問(wèn)題
- nginx將https協(xié)議反向代理到http協(xié)議請(qǐng)求上的實(shí)現(xiàn)
- 如何實(shí)現(xiàn)Nginx同一端口同時(shí)支持http與https協(xié)議
- nginx將https協(xié)議反向代理到http協(xié)議請(qǐng)求上
- Nginx服務(wù)器配置https安全協(xié)議的實(shí)現(xiàn)
- Nginx內(nèi)網(wǎng)環(huán)境開啟https雙協(xié)議
相關(guān)文章
Centos 6.5環(huán)境實(shí)現(xiàn)本地局域網(wǎng)搭建YUM的方法【基于HTTP】
這篇文章主要介紹了Centos 6.5環(huán)境實(shí)現(xiàn)本地局域網(wǎng)搭建YUM的方法,較為詳細(xì)的分析了CentOS6.5基于HTTP實(shí)現(xiàn)本地局域網(wǎng)搭建YUM的具體步驟、相關(guān)命令與操作注意事項(xiàng),需要的朋友可以參考下2018-04-04linux如何利用crontab添加定時(shí)任務(wù)詳解
這篇文章主要給大家介紹了關(guān)于linux如何利用crontab添加定時(shí)任務(wù)的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用linux具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04linux系統(tǒng)報(bào)tcp_mark_head_lost錯(cuò)誤的處理方法
這篇文章主要給大家介紹了關(guān)于linux系統(tǒng)報(bào)tcp_mark_head_lost錯(cuò)誤的處理方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用linux系統(tǒng)具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07CentOS 7.x下的LEMP環(huán)境搭建詳細(xì)教程
我們常說(shuō)的LNMP環(huán)境是指Linux/nginx/MySQL/PHP組合,LEMP包是由Linux、nginx、MariaDB/MySQL和PHP組成的,那么看來(lái)LEMP和LNMP是一樣的,而現(xiàn)在業(yè)內(nèi)習(xí)慣性的稱作LEMP。這篇文章主要介紹了CentOS 7.x下的LEMP環(huán)境搭建詳細(xì)教程,需要的朋友可以參考下2016-10-10CentOS 7.2搭建VNC遠(yuǎn)程桌面服務(wù)的方法
本篇文章主要介紹了CentOS 7.2搭建VNC遠(yuǎn)程桌面服務(wù)的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-03-03Windows下PHP安裝路徑配置錯(cuò)誤導(dǎo)致Apache無(wú)法啟動(dòng)的解決方法
這篇文章主要介紹了Windows下PHP安裝路徑配置錯(cuò)誤導(dǎo)致Apache無(wú)法啟動(dòng)的解決方法,本文可以說(shuō)是一個(gè)引號(hào)引發(fā)的悲劇,需要的朋友可以參考下2014-09-09